<?php

namespace App\Http\Requests\Admin\Finance;

use App\Concerns\CurrencyStripping;
use Illuminate\Foundation\Http\FormRequest;
use Override;

class EmployeeAdvanceRequest extends FormRequest
{
    use CurrencyStripping;

    public function authorize(): bool
    {
        return $this->user()->can('employee_advances.create')
            || $this->user()->can('employee_advances.update');
    }

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

    public function rules(): array
    {
        return [
            'amount' => ['required', 'integer', 'min:1'],
            'description' => ['required', 'string', 'max:100'],
            'due_date' => ['required', 'date', 'after_or_equal:today'],
        ];
    }

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