<?php

declare(strict_types=1);

namespace App\Http\Requests\Studio;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

final class ApplyArtworkAiAssistRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    public function rules(): array
    {
        return [
            'title' => ['sometimes', 'nullable', 'string', 'max:255'],
            'title_mode' => ['sometimes', Rule::in(['replace', 'insert'])],
            'description' => ['sometimes', 'nullable', 'string', 'max:5000'],
            'description_mode' => ['sometimes', Rule::in(['replace', 'append'])],
            'tags' => ['sometimes', 'array', 'max:15'],
            'tags.*' => ['string', 'max:64'],
            'tag_mode' => ['sometimes', Rule::in(['add', 'replace', 'remove'])],
            'category_id' => ['sometimes', 'nullable', 'integer', 'exists:categories,id'],
            'content_type_id' => ['sometimes', 'nullable', 'integer', 'exists:content_types,id'],
            'similar_actions' => ['sometimes', 'array', 'max:10'],
            'similar_actions.*.artwork_id' => ['required_with:similar_actions', 'integer'],
            'similar_actions.*.state' => ['required_with:similar_actions', Rule::in(['ignored', 'reviewed'])],
        ];
    }
}