<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreEmailTemplateRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', \App\Models\EmailTemplate::class) ?? false;
    }

    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'key' => ['required', 'string', 'max:255', 'unique:email_templates,key'],
            'subject_template' => ['required', 'string', 'max:1000'],
            'html_template' => ['nullable', 'string'],
            'text_template' => ['nullable', 'string'],
            'entity_types' => ['nullable', 'array'],
            'entity_types.*' => ['string', 'in:client,client_case,contract,person'],
            'allow_attachments' => ['sometimes', 'boolean'],
            'active' => ['boolean'],
            'client' => ['sometimes', 'boolean'],
            'action_id' => ['nullable', 'integer', 'exists:actions,id'],
            'decision_id' => ['nullable', 'integer', 'exists:decisions,id'],
        ];
    }
}
