<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StorePackageFromContractsRequest 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'],

            // Common payload for all items
            'payload' => ['required', 'array'],
            'payload.profile_id' => ['nullable', 'integer', 'exists:sms_profiles,id'],
            'payload.sender_id' => ['nullable', 'integer', 'exists:sms_senders,id'],
            'payload.template_id' => ['nullable', 'integer', 'exists:sms_templates,id'],
            'payload.delivery_report' => ['nullable', 'boolean'],
            'payload.variables' => ['nullable', 'array'],
            'payload.body' => ['nullable', 'string'],

            // Source contracts to derive items from
            'contract_ids' => ['required', 'array', 'min:1'],
            'contract_ids.*' => ['integer', 'exists:contracts,id'],
        ];
    }
}
