<?php

namespace App\Http\Controllers;

use App\Models\ClassWiseFee;
use App\Models\SchoolClass;
use App\Models\FeeType;
use Illuminate\Http\Request;

class ClassWiseFeeController extends Controller
{
    public function index() {
        $fees = ClassWiseFee::with(['schoolClass', 'feeType'])->get();
        $classes = SchoolClass::all();
        $feeTypes = FeeType::all();
        return view('admin.class_fees', compact('fees', 'classes', 'feeTypes'));
    }

    public function store(Request $request) {
        ClassWiseFee::updateOrCreate(
            ['class_id' => $request->class_id, 'fee_type_id' => $request->fee_type_id],
            ['default_amount' => $request->default_amount]
        );
        return response()->json(['status' => 'success', 'message' => 'ফি সেটআপ সফল হয়েছে!']);
    }

    public function destroy($id) {
        ClassWiseFee::destroy($id);
        return response()->json(['status' => 'success']);
    }
}