<?php

namespace App\Http\Controllers\Admin\Finance\Payroll;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Finance\PayrollAdjustmentRequest;
use App\Models\Payroll;
use App\Models\PayrollAdjustment;
use App\Services\Admin\Finance\Payroll\PayrollAdjustmentService;
use Illuminate\Http\RedirectResponse;

class PayrollAdjustmentController extends Controller
{
    public function __construct(
        private PayrollAdjustmentService $service
    ) {}

    public function store(PayrollAdjustmentRequest $request, Payroll $payroll): RedirectResponse
    {
        return $this->handleAction(
            fn () => $this->service->store($payroll, $request->validated()),
            'Adjustment gaji berhasil ditambahkan.',
            'admin.finance.payroll-periods.show',
            parameters: ['payroll_period' => $payroll->payroll_period_id]
        );
    }

    public function destroy(PayrollAdjustment $payrollAdjustment): RedirectResponse
    {
        return $this->handleAction(
            fn () => $this->service->destroy($payrollAdjustment),
            'Adjustment gaji berhasil dihapus.',
            'admin.finance.payroll-periods.show',
            parameters: ['payroll_period' => $payrollAdjustment->payroll->payroll_period_id]
        );
    }
}
