<?php

namespace App\Http\Requests\Notification;

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

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

    public function rules(): array
    {
        return [
            'preferences' => ['required', 'array'],
            'preferences.*.tenant_id' => ['nullable', 'integer', 'exists:tenants,id'],
            'preferences.*.notification_event_id' => ['required', 'integer', 'exists:notification_events,id'],
            'preferences.*.notification_channel_id' => ['nullable', 'integer', 'exists:notification_channels,id'],
            'preferences.*.channel' => ['required', Rule::in(['system', 'whatsapp_official', 'whatsapp_unofficial', 'email', 'telegram'])],
            'preferences.*.enabled' => ['required', 'boolean'],
            'preferences.*.priority' => ['nullable', 'integer', 'between:1,20'],
            'preferences.*.send_delay_minutes' => ['nullable', 'integer', 'between:0,10080'],
            'preferences.*.quiet_hours_start' => ['nullable', 'date_format:H:i'],
            'preferences.*.quiet_hours_end' => ['nullable', 'date_format:H:i'],
        ];
    }
}
