<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Banks;

class bankController extends Controller
{
    public function store(Request $request)
    {
        $request->validate([
            'bank_name' => 'required|string|max:255|unique:banks,bank_name',
        ]);

        $bank = new Banks();
        $bank->bank_name = $request->input('bank_name');
        $bank->save();

        return response()->json(['message' => 'Bank created successfully'], 201);
    }

    public function index()
    {
        $banks = Banks::all();
        return response()->json($banks);
    }
    public function update(Request $request, $id)
    {
        $request->validate([
            'bank_name' => 'required|string|max:255|unique:banks,bank_name,' . $id,
        ]);

        $bank = Banks::findOrFail($id);
        $bank->bank_name = $request->input('bank_name');
        $bank->save();

        return response()->json(['message' => 'Bank updated successfully']);
    }
}
