<?php

declare(strict_types=1);

namespace App\Http\Requests\Academy;

use Illuminate\Foundation\Http\FormRequest;

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

    protected function prepareForValidation(): void
    {
        $this->merge([
            'artwork_id' => $this->filled('artwork_id') ? (int) $this->input('artwork_id') : null,
            'is_ai_generated' => $this->boolean('is_ai_generated'),
            'is_ai_assisted' => $this->boolean('is_ai_assisted', true),
        ]);
    }

    public function rules(): array
    {
        return [
            'artwork_id' => ['required', 'integer', 'exists:artworks,id'],
            'prompt_used' => ['nullable', 'string'],
            'workflow_notes' => ['nullable', 'string'],
            'ai_tool_used' => ['nullable', 'string', 'max:120'],
            'is_ai_generated' => ['required', 'boolean'],
            'is_ai_assisted' => ['required', 'boolean'],
        ];
    }
}