<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\EmployeeAllowance;
use Illuminate\Http\Request;

class EmployeeAllowanceController extends Controller
{
    // Mengambil tunjangan spesifik untuk satu karyawan
    public function show($employeeId) {
        return response()->json([
            'success' => true, 
            'data' => EmployeeAllowance::with('allowanceType') // Pastikan relasi sudah ada di model
                                        ->where('employee_id', $employeeId)
                                        ->get()
        ]);
    }

    // Menyimpan tunjangan baru ke karyawan
    public function store(Request $request) {
        $request->validate([
            'employee_id' => 'required',
            'allowance_type_id' => 'required',
            'amount' => 'required|numeric',
            'start_date' => 'required|date'
        ]);

        $allowance = EmployeeAllowance::create($request->all());
        return response()->json(['success' => true, 'data' => $allowance]);
    }
}