<?php

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

use App\Http\Controllers\Controller;
use App\Models\Payroll;
use App\Services\Admin\Finance\Payroll\PayrollPeriodService;
use Illuminate\Http\RedirectResponse;

class PayrollController extends Controller
{
    public function __construct(
        private PayrollPeriodService $service
    ) {}

    public function pay(Payroll $payroll): RedirectResponse
    {
        return $this->handleAction(
            fn () => $this->service->pay($payroll),
            'Gaji berhasil dibayar.',
            'admin.finance.payroll-periods.show',
            parameters: ['payroll_period' => $payroll->payroll_period_id]
        );
    }

    public function cancel(Payroll $payroll): RedirectResponse
    {
        return $this->handleAction(
            fn () => $this->service->cancel($payroll),
            'Gaji berhasil dibatalkan.',
            'admin.finance.payroll-periods.show',
            parameters: ['payroll_period' => $payroll->payroll_period_id]
        );
    }
}
