<?php

use MintyPHP\Domain\Taxonomy\MailLogStatus;

$mailLogStatusItems = array_map(
    static fn (MailLogStatus $status): array => [
        'id' => $status->value,
        'description' => $status->labelToken(),
    ],
    MailLogStatus::cases()
);

return gridFilterSchema([
    'query' => [
        'limit' => ['type' => 'int', 'default' => 10, 'min' => 1, 'max' => 100],
        'offset' => ['type' => 'int', 'default' => 0, 'min' => 0],
        'search' => ['type' => 'string'],
        'order' => ['type' => 'order', 'allowed' => ['created_at', 'status', 'to_email', 'subject'], 'default' => 'created_at'],
        'dir' => ['type' => 'dir', 'default' => 'desc'],
        'status' => ['type' => 'enum', 'allowed' => MailLogStatus::values(), 'default' => '', 'lowercase' => true],
        'created_from' => ['type' => 'date'],
        'created_to' => ['type' => 'date'],
    ],
    'toolbar' => [
        [
            'key' => 'search',
            'type' => 'text',
            'label' => 'Search',
            'placeholder' => 'Search...',
            'input_id' => 'mail-log-search',
            'search' => true,
            'query' => ['type' => 'string'],
        ],
        [
            'key' => 'status',
            'type' => 'select',
            'label' => 'Status',
            'input_id' => 'mail-log-status-filter',
            'default' => '',
            'allowed' => [
                ['id' => '', 'description' => 'All statuses'],
                ...$mailLogStatusItems,
            ],
        ],
        [
            'key' => 'created_from',
            'type' => 'date',
            'label' => 'Created from',
            'input_id' => 'mail-log-created-from',
        ],
        [
            'key' => 'created_to',
            'type' => 'date',
            'label' => 'Created to',
            'input_id' => 'mail-log-created-to',
        ],
    ],
]);
