<?php

namespace App\Http\Requests\Api\V1;

use Illuminate\Foundation\Http\FormRequest;

class SetPermissionsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'user_id' => ['sometimes', 'exists:users,id'],
            'role' => ['sometimes', 'in:super_admin,admin,user'],
            'permission' => ['required', 'in:view,download,manage'],
            'expires_at' => ['sometimes', 'date', 'after:now'],
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'user_id.exists' => 'The specified user does not exist.',
            'role.in' => 'Role must be one of: super_admin, admin, user.',
            'permission.required' => 'A permission level is required.',
            'permission.in' => 'Permission must be one of: view, download, manage.',
            'expires_at.after' => 'The expiration date must be in the future.',
        ];
    }
}
