<?php

namespace App\Rules;

use App\Models\Usuario;
use Illuminate\Validation\Rule;

class UserRules
{
    public static function rules(bool $isUpdate = false, $id = null): array
    {
        $uniqueCedula = $isUpdate
            ? ['required', 'string', 'max:20', Rule::unique('users', 'cedula')->ignore($id)]
            : ['required', 'string', 'max:20', 'unique:users,cedula'];
        $passwordRules = $isUpdate
            ? ['nullable', 'string', 'min:8', 'alpha_num']
            : ['required', 'string', 'min:8', 'alpha_num'];

        return [
            'cedula' => $uniqueCedula,
            'password' => $passwordRules,
            'nombre' => ['required', 'string', 'max:200'],
            'cargo' => ['required', 'string', 'max:200', Rule::in(array_values(Usuario::ROLE_LABELS))],
            'codigo' => ['nullable', 'string', 'max:50'],
            'dependencia' => ['nullable', 'string', 'max:200'],
            'fechaIngreso' => ['required', 'date'],
            'tipo' => ['nullable', 'integer', Rule::in(array_values(Usuario::ROLE_TYPE_MAP))],
            'fotoUsuario' => ['nullable', 'file', 'mimes:jpg,jpeg,png,webp', 'max:4096'],
        ];
    }
}
