<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\Offers\Http\Requests;

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

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

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'channels' => ['required', 'array', 'min:1'],
            'channels.*' => ['string', 'in:link,pdf,email'],
            'email' => ['nullable', 'array'],
            'email.to' => [
                Rule::requiredIf(fn (): bool => in_array('email', (array) $this->input('channels', []), true)),
                'nullable',
                'string',
                'max:320',
            ],
            'email.subject' => ['nullable', 'string', 'max:255'],
        ];
    }
}
