<?php

namespace App\Http\Requests\Role;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules()
    {
        return [
            'name' => 'required|string|max:50',
            'code' => 'required|string|max:50|unique:admin_roles,code',
            'description' => 'nullable|string|max:255',
            'parent_id' => 'nullable|integer|in:0,'.\App\Models\AdminRole::pluck('id')->implode(','),
            'sort' => 'nullable|integer|min:0',
            'status' => 'nullable|in:0,1',
            'permission_ids' => 'nullable|array',
            'permission_ids.*' => 'exists:admin_permissions,id',
            'menu_ids' => 'nullable|array',
            'menu_ids.*' => 'exists:admin_menus,id',
        ];
    }

    public function attributes()
    {
        return [
            'name' => '角色名称',
            'code' => '角色代码',
            'description' => '描述',
            'parent_id' => '父角色',
            'sort' => '排序',
            'status' => '状态',
            'permission_ids' => '权限',
            'menu_ids' => '菜单',
        ];
    }
}
