<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\SettingMalaysiaBank;

class SettingMalaysiaBankController extends Controller
{
    public function index()
    {
        return SettingMalaysiaBank::all();
    }

    public function show(SettingMalaysiaBank $malaysiaBank)
    {
        return $malaysiaBank;
    }

    public function store(Request $request)
    {
        $malaysiaBank = SettingMalaysiaBank::create($request->all());

        return response()->json($malaysiaBank, 201);
    }

    public function update(Request $request, SettingMalaysiaBank $malaysiaBank)
    {
        $malaysiaBank->update($request->all());

        return response()->json($malaysiaBank, 200);
    }

    public function delete(SettingMalaysiaBank $malaysiaBank)
    {
        $malaysiaBank->delete();

        return response()->json(null, 204);
    }

    public function updateStatus(string $id, SettingMalaysiaBank $malaysiaBank){
        $currentRecord = SettingMalaysiaBank::where('id', $id)->first();
        SettingMalaysiaBank::where('id', $id)->update(['active' => $currentRecord->active === 1 ? 0 : 1]);
        return response()->json(SettingMalaysiaBank::all(), 200);
    }
}
