<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StorePackageRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('manage-settings') ?? false;
    }

    public function rules(): array
    {
        return [
            'type' => ['required', 'in:sms'],
            'name' => ['nullable', 'string', 'max:255'],
            'description' => ['nullable', 'string'],
            'meta' => ['nullable', 'array'],

            // items
            'items' => ['required', 'array', 'min:1'],
            'items.*.number' => ['required', 'string'],
            'items.*.phone_id' => ['nullable', 'integer'],
            'items.*.payload' => ['nullable', 'array'],
            'items.*.payload.profile_id' => ['nullable', 'integer', 'exists:sms_profiles,id'],
            'items.*.payload.sender_id' => ['nullable', 'integer', 'exists:sms_senders,id'],
            'items.*.payload.template_id' => ['nullable', 'integer', 'exists:sms_templates,id'],
            'items.*.payload.delivery_report' => ['nullable', 'boolean'],
            'items.*.payload.variables' => ['nullable', 'array'],
            'items.*.payload.body' => ['nullable', 'string'],
        ];
    }
}
