<?php

use MintyPHP\Domain\Taxonomy\ScheduledJobStatus;

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

return gridFilterSchema([
    'query' => [
        'limit' => ['type' => 'int', 'default' => 20, 'min' => 1, 'max' => 200],
        'offset' => ['type' => 'int', 'default' => 0, 'min' => 0],
        'search' => ['type' => 'string'],
        'enabled' => ['type' => 'string'],
        'status' => ['type' => 'enum', 'allowed' => ScheduledJobStatus::values(), 'default' => '', 'lowercase' => true],
        'order' => ['type' => 'order', 'allowed' => ['job_key', 'enabled', 'next_run_at', 'last_run_finished_at', 'last_run_status'], 'default' => 'job_key'],
        'dir' => ['type' => 'dir', 'default' => 'asc'],
    ],
    'toolbar' => [
        [
            'key' => 'search',
            'type' => 'text',
            'label' => 'Search',
            'placeholder' => 'Search...',
            'input_id' => 'scheduled-jobs-search',
            'search' => true,
            'query' => ['type' => 'string'],
        ],
        [
            'key' => 'enabled',
            'type' => 'select',
            'label' => 'Enabled',
            'input_id' => 'scheduled-jobs-enabled-filter',
            'default' => '',
            'allowed' => [
                ['id' => '', 'description' => 'All'],
                ['id' => '1', 'description' => 'Enabled'],
                ['id' => '0', 'description' => 'Disabled'],
            ],
        ],
        [
            'key' => 'status',
            'type' => 'select',
            'label' => 'Status',
            'input_id' => 'scheduled-jobs-status-filter',
            'default' => '',
            'allowed' => [
                ['id' => '', 'description' => 'All statuses'],
                ...$scheduledJobStatusItems,
            ],
        ],
    ],
]);
