<?php

namespace App\Modules\HR\EmploymentStatuses\Requests;

use App\Modules\HR\EmploymentStatuses\Models\EmploymentStatus;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreEmploymentStatusRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', EmploymentStatus::class) ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return $this->baseRules();
    }

    /**
     * @return array<string, mixed>
     */
    protected function baseRules(): array
    {
        $colors = config('hr_employment_statuses.allowed_colors', []);

        return [
            'name' => ['required', 'string', 'max:120'],
            'description' => ['nullable', 'string'],
            'color' => ['required', 'string', Rule::in($colors)],
            'sort_order' => ['nullable', 'integer', 'min:0'],
            'is_active' => ['sometimes', 'boolean'],
        ];
    }
}
