<?php

use MintyPHP\Module\Audit\Domain\ImportAuditStatus;

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

return gridFilterSchema([
    'query' => [
        'limit' => ['type' => 'int', 'default' => 20, 'min' => 1, 'max' => 200],
        'offset' => ['type' => 'int', 'default' => 0, 'min' => 0],
        'search' => ['type' => 'string'],
        'profile_key' => ['type' => 'enum', 'allowed' => ['users', 'departments'], 'default' => '', 'lowercase' => true],
        'status' => ['type' => 'enum', 'allowed' => ImportAuditStatus::values(), 'default' => '', 'lowercase' => true],
        'created_from' => ['type' => 'date'],
        'created_to' => ['type' => 'date'],
        'user_ids' => ['type' => 'csv_ids', 'max' => 200],
        'order' => ['type' => 'order', 'allowed' => ['started_at', 'status', 'profile_key', 'duration_ms', 'rows_total', 'created_count', 'skipped_count', 'failed_count'], 'default' => 'started_at'],
        'dir' => ['type' => 'dir', 'default' => 'desc'],
    ],
    'toolbar' => [
        [
            'key' => 'search',
            'type' => 'text',
            'label' => 'Search',
            'placeholder' => 'Search...',
            'input_id' => 'import-audit-search',
            'search' => true,
            'query' => ['type' => 'string'],
        ],
        [
            'key' => 'profile_key',
            'type' => 'select',
            'label' => 'Profile',
            'input_id' => 'import-audit-profile-filter',
            'default' => '',
            'allowed' => [
                ['id' => '', 'description' => 'All profiles'],
                ['id' => 'users', 'description' => 'Users'],
                ['id' => 'departments', 'description' => 'Departments'],
            ],
        ],
        [
            'key' => 'status',
            'type' => 'select',
            'label' => 'Status',
            'input_id' => 'import-audit-status-filter',
            'default' => '',
            'allowed' => [
                ['id' => '', 'description' => 'All statuses'],
                ...$importAuditStatusItems,
            ],
        ],
        [
            'key' => 'created_from',
            'type' => 'date',
            'label' => 'Created from',
            'input_id' => 'import-audit-created-from',
        ],
        [
            'key' => 'created_to',
            'type' => 'date',
            'label' => 'Created to',
            'input_id' => 'import-audit-created-to',
        ],
        [
            'key' => 'user_ids',
            'type' => 'multi_csv',
            'label' => 'Users',
            'placeholder' => 'Select users',
            'input_id' => 'import-audit-user-ids-filter',
            'options_key' => 'user_items',
            'default' => [],
            'query' => ['type' => 'csv_ids', 'max' => 200, 'return' => 'array'],
        ],
    ],
]);
