<?php

namespace App\Modules\HR\Employees\Requests;

use App\Modules\HR\Employees\Models\Employee;
use App\Modules\HR\Employees\Support\EmployeeAssetStatus;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreEmployeeAssetRequest extends FormRequest
{
    public function authorize(): bool
    {
        /** @var Employee $employee */
        $employee = $this->route('employee');

        return $this->user()?->can('update', $employee) ?? false;
    }

    /** @return array<string, mixed> */
    public function rules(): array
    {
        return [
            'asset_code' => ['required', 'string', 'max:120'],
            'asset_name' => ['required', 'string', 'max:255'],
            'category' => ['nullable', 'string', 'max:120'],
            'assigned_at' => ['required', 'date'],
            'returned_at' => ['nullable', 'date', 'after_or_equal:assigned_at'],
            'status' => ['required', 'string', Rule::in(EmployeeAssetStatus::all())],
            'notes' => ['nullable', 'string', 'max:500'],
            'external_asset_id' => ['nullable', 'integer', 'min:1'],
        ];
    }
}
