<?php

namespace App\Http\Requests\Content;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'name' => 'required|string|max:50',
            'alias' => 'required|string|max:50|regex:/^[a-z][a-z0-9_]*$/|unique:content_models,alias',
            'description' => 'nullable|string|max:255',
            'sort' => 'integer|min:0',
            'status' => 'integer|in:0,1',
        ];
    }

    public function attributes(): array
    {
        return [
            'name' => '模型名称',
            'alias' => '模型别名',
            'description' => '描述',
            'sort' => '排序',
            'status' => '状态',
        ];
    }

    public function messages(): array
    {
        return [
            'name.required' => '请输入模型名称',
            'name.max' => '模型名称不能超过50个字符',
            'alias.required' => '请输入模型别名',
            'alias.max' => '模型别名不能超过50个字符',
            'alias.regex' => '模型别名只能包含小写字母、数字和下划线，且以小写字母开头',
            'alias.unique' => '模型别名已存在',
            'description.max' => '描述不能超过255个字符',
            'sort.min' => '排序值不能小于0',
            'status.in' => '状态值无效',
        ];
    }
}
