<?php

declare(strict_types=1);

namespace App\Http\Requests;

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

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

    /** @return array<string, array<int, mixed>> */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'cancellation_reason' => ['nullable', 'string', 'max:100'],
            'email_sequence' => ['required', 'array', 'min:1'],
            'email_sequence.*.delay_days' => ['required', 'integer', 'min:0'],
            'email_sequence.*.subject' => ['required', 'string', 'max:255'],
            'email_sequence.*.body' => ['required', 'string'],
            'offer_type' => ['required', Rule::in(['discount', 'credit', 'free_upgrade', 'none'])],
            'offer_value' => ['nullable', 'numeric', 'min:0'],
            'offer_duration_days' => ['nullable', 'integer', 'min:1'],
            'coupon_code' => ['nullable', 'string', 'max:50'],
            'status' => ['required', Rule::in(['active', 'paused', 'archived'])],
        ];
    }

    /** @return array<string, string> */
    public function messages(): array
    {
        return [
            'name.required' => 'Campaign name is required.',
            'email_sequence.required' => 'At least one email must be defined.',
            'email_sequence.min' => 'At least one email must be defined.',
            'email_sequence.*.delay_days.required' => 'Delay days is required for each email.',
            'email_sequence.*.delay_days.min' => 'Delay days must be at least 0.',
            'email_sequence.*.subject.required' => 'Subject is required for each email.',
            'email_sequence.*.body.required' => 'Body is required for each email.',
            'offer_type.required' => 'Offer type is required.',
            'offer_type.in' => 'Offer type must be discount, credit, free_upgrade, or none.',
            'status.required' => 'Status is required.',
            'status.in' => 'Status must be active, paused, or archived.',
        ];
    }
}
