<?php

namespace App\Http\Requests\Content;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'category_id' => 'nullable|integer|exists:content_categories,id',
            'title' => 'nullable|string|max:200',
            'content' => 'nullable|string',
            'summary' => 'nullable|string|max:500',
            'image' => 'nullable|string|max:255',
            'author' => 'nullable|string|max:50',
            'source' => 'nullable|string|max:100',
            'publish_at' => 'nullable|date',
            'sort' => 'nullable|integer|min:0',
            'status' => 'nullable|integer|in:0,1,2',
            'extension' => 'nullable|array',
        ];
    }

    public function attributes(): array
    {
        return [
            'category_id' => '所属分类',
            'title' => '标题',
            'content' => '内容',
            'summary' => '摘要',
            'image' => '封面图',
            'author' => '作者',
            'source' => '来源',
            'publish_at' => '发布时间',
            'sort' => '排序',
            'status' => '状态',
        ];
    }

    public function messages(): array
    {
        return [
            'category_id.exists' => '所属分类不存在',
            'title.max' => '标题不能超过200个字符',
            'summary.max' => '摘要不能超过500个字符',
            'image.max' => '封面图路径不能超过255个字符',
            'author.max' => '作者不能超过50个字符',
            'source.max' => '来源不能超过100个字符',
            'publish_at.date' => '发布时间格式无效',
            'sort.min' => '排序值不能小于0',
            'status.in' => '状态值无效',
        ];
    }
}
