<?php

namespace App\Http\Requests\Admin\Finance;

use App\Concerns\CurrencyStripping;
use App\Enums\PayrollAdjustmentType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Override;

class PayrollAdjustmentRequest extends FormRequest
{
    use CurrencyStripping;

    public function authorize(): bool
    {
        return $this->user()->can('payroll.adjust');
    }

    #[Override]
    public function prepareForValidation(): void
    {
        $this->merge($this->stripCurrencyDot($this->all(), 'amount'));
    }

    public function rules(): array
    {
        return [
            'type' => ['required', Rule::in(PayrollAdjustmentType::values())],
            'amount' => ['required', 'integer', 'min:1'],
            'description' => ['required', 'string', 'max:100'],
        ];
    }

    public function attributes(): array
    {
        return [
            'type' => 'jenis',
            'amount' => 'jumlah',
            'description' => 'keterangan',
        ];
    }
}
