<?php

namespace App\Http\Requests\Content;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'name' => 'required|string|max:50',
            'field' => 'prohibited',
            'type' => 'required|string|in:varchar,text,longtext,int,decimal,date,datetime,json',
            'length' => 'nullable|integer|min:1',
            'decimal_precision' => 'nullable|integer|min:0|max:10',
            'default_value' => 'nullable|string|max:255',
            'form_type' => 'required|string|in:text,textarea,tinymce,select,radio,checkbox,switch,date,datetime,image,file,number,color,tags',
            'form_config' => 'nullable|array',
            'sort' => 'integer|min:0',
            'status' => 'integer|in:0,1',
        ];
    }

    public function attributes(): array
    {
        return [
            'name' => '字段名称',
            'field' => '字段标识',
            'type' => '字段类型',
            'length' => '字段长度',
            'decimal_precision' => '小数精度',
            'default_value' => '默认值',
            'form_type' => '表单类型',
            'form_config' => '表单配置',
            'sort' => '排序',
            'status' => '状态',
        ];
    }

    public function messages(): array
    {
        return [
            'name.required' => '请输入字段名称',
            'name.max' => '字段名称不能超过50个字符',
            'field.prohibited' => '字段标识不允许修改',
            'type.required' => '请选择字段类型',
            'type.in' => '字段类型无效',
            'length.min' => '字段长度不能小于1',
            'decimal_precision.min' => '小数精度不能小于0',
            'decimal_precision.max' => '小数精度不能超过10',
            'default_value.max' => '默认值不能超过255个字符',
            'form_type.required' => '请选择表单类型',
            'form_type.in' => '表单类型无效',
            'form_config.array' => '表单配置格式错误',
            'sort.min' => '排序值不能小于0',
            'status.in' => '状态值无效',
        ];
    }
}
