<?php

namespace App\Http\Requests\Admin;

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

class EmailCampaignUpdateRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('update', $this->route('emailCampaign'));
    }

    public function rules(): array
    {
        return [
            'email_marketing_list_id' => 'nullable|integer|exists:email_marketing_lists,id',
            'name' => 'required|string|max:255',
            'subject' => 'nullable|string|max:255',
            'from_name' => 'nullable|string|max:255',
            'from_email' => 'nullable|email|max:255',
            'reply_to' => 'nullable|email|max:255',
            'status' => 'in:draft,scheduled,sending,sent,paused,failed',
            'scheduled_at' => 'nullable|date',
            'content_type' => 'in:template,html',
            'template_id' => ['nullable', 'integer', Rule::exists('communication_templates', 'id')->where('channel', 'email')],
            'content_html' => 'nullable|string',
        ];
    }
}
