<?php

namespace App\Http\Requests\Concerns;

use App\NotificationMaps\NotificationPayloadMapper;
use Illuminate\Validation\Rule;

/**
 * Shared validation rules for the field_map / validation / config structure used by
 * both NotificationTemplate and NotificationMap requests.
 */
trait ValidatesNotificationMapStructure
{
    /**
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    protected function structureRules(): array
    {
        return [
            'field_map' => ['nullable', 'array'],
            'field_map.*.source' => ['required', 'string', 'max:255'],
            'field_map.*.destination' => ['required', 'string', 'max:255'],
            'field_map.*.type' => ['nullable', 'string', Rule::in(NotificationPayloadMapper::TYPES)],
            'validation' => ['nullable', 'array'],
            'validation.*' => ['array'],
            'validation.*.*' => ['string'],
            'config' => ['nullable', 'array'],
        ];
    }
}
