<?php

namespace App\Http\Requests\Admin\Role;

use Illuminate\Foundation\Http\FormRequest;

class StoreRoleRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'name'          => ['required', 'string', 'max:255', 'unique:roles,name'],
            'permissions'   => ['required', 'array', 'min:1'],
            'permissions.*' => ['string', 'exists:permissions,name'],
        ];
    }

    public function attributes(): array
    {
        return [
            'name'        => __('dashboard.role_name'),
            'permissions' => __('dashboard.permissions'),
        ];
    }

    public function messages(): array
    {
        return [
            'permissions.required' => __('dashboard.select_at_least_one_permission'),
            'permissions.min'      => __('dashboard.select_at_least_one_permission'),
        ];
    }
}
