<?php

/**
 * Audit module manifest.
 *
 * Provides four audit streams: system audit, API audit, import audit,
 * and user lifecycle audit. Includes frontend telemetry ingestion,
 * PII redaction, encrypted snapshots, and retention-based cleanup.
 */
return [
    'id' => 'audit',
    'version' => '1.0.0',
    'enabled_by_default' => true,
    'load_order' => 5,
    'requires' => [],

    'routes' => [
        // API audit pages
        ['path' => 'admin/api-audit', 'target' => 'audit/api-audit/index'],
        ['path' => 'admin/api-audit/view', 'target' => 'audit/api-audit/view'],
        ['path' => 'admin/api-audit/data', 'target' => 'audit/api-audit/data'],
        ['path' => 'admin/api-audit/purge', 'target' => 'audit/api-audit/purge'],
        // System audit pages
        ['path' => 'admin/system-audit', 'target' => 'audit/system-audit/index'],
        ['path' => 'admin/system-audit/view', 'target' => 'audit/system-audit/view'],
        ['path' => 'admin/system-audit/data', 'target' => 'audit/system-audit/data'],
        ['path' => 'admin/system-audit/export', 'target' => 'audit/system-audit/export'],
        ['path' => 'admin/system-audit/purge', 'target' => 'audit/system-audit/purge'],
        // Import audit pages
        ['path' => 'admin/import-audit', 'target' => 'audit/import-audit/index'],
        ['path' => 'admin/import-audit/view', 'target' => 'audit/import-audit/view'],
        ['path' => 'admin/import-audit/data', 'target' => 'audit/import-audit/data'],
        ['path' => 'admin/import-audit/purge', 'target' => 'audit/import-audit/purge'],
        // User lifecycle audit endpoints embedded in admin/settings/user-lifecycle
        ['path' => 'admin/settings/user-lifecycle/audit-data', 'target' => 'audit/settings-user-lifecycle/audit-data'],
        ['path' => 'admin/settings/user-lifecycle/audit-fragment', 'target' => 'audit/settings-user-lifecycle/audit-fragment'],
        ['path' => 'admin/settings/user-lifecycle/audit-restore', 'target' => 'audit/settings-user-lifecycle/audit-restore'],
        ['path' => 'admin/settings/user-lifecycle/audit-purge', 'target' => 'audit/settings-user-lifecycle/audit-purge'],
        // Frontend telemetry
        ['path' => 'admin/frontend-telemetry/ingest', 'target' => 'audit/frontend-telemetry/ingest'],
    ],
    'public_paths' => [],

    'container_registrars' => [
        \MintyPHP\Module\Audit\AuditContainerRegistrar::class,
    ],

    'ui_slots' => [
        'sidebar.admin_nav_item' => [
            [
                'key' => 'audit-api-audit',
                'group' => 'admin-logs',
                'label' => 'nav.audit.api',
                'path' => 'audit/api-audit',
                'permission' => 'audit.api.view',
                'order' => 200,
            ],
            [
                'key' => 'audit-system-audit',
                'group' => 'admin-logs',
                'label' => 'nav.audit.system',
                'path' => 'audit/system-audit',
                'permission' => 'audit.system.view',
                'order' => 210,
            ],
            [
                'key' => 'audit-import-audit',
                'group' => 'admin-logs',
                'label' => 'nav.audit.imports',
                'path' => 'audit/import-audit',
                'permission' => 'audit.imports.view',
                'order' => 220,
            ],
        ],
        'settings.user_lifecycle.panel' => [
            [
                'key' => 'audit-settings-user-lifecycle-panel',
                'template' => 'templates/settings-user-lifecycle-panel.phtml',
                'permission' => 'audit.user_lifecycle.view',
                'order' => 100,
            ],
        ],
    ],

    'authorization_policies' => [
        \MintyPHP\Module\Audit\AuditAuthorizationPolicy::class,
    ],

    'permissions' => [
        [
            'key' => 'audit.api.view',
            'description' => 'View API audit logs',
        ],
        [
            'key' => 'audit.system.view',
            'description' => 'View system audit logs',
        ],
        [
            'key' => 'audit.system.purge',
            'description' => 'Purge system audit logs',
        ],
        [
            'key' => 'audit.api.purge',
            'description' => 'Purge API audit logs',
        ],
        [
            'key' => 'audit.imports.view',
            'description' => 'View import audit logs',
        ],
        [
            'key' => 'audit.imports.purge',
            'description' => 'Purge import audit logs',
        ],
        [
            'key' => 'audit.user_lifecycle.view',
            'description' => 'View user lifecycle audit logs',
        ],
        [
            'key' => 'audit.user_lifecycle.restore',
            'description' => 'Restore deleted users from lifecycle audit',
        ],
    ],

    'scheduler_jobs' => [
        [
            'job_key' => 'system_audit_purge',
            'handler' => \MintyPHP\Module\Audit\Handler\SystemAuditPurgeJobHandler::class,
            'label' => 'System audit log cleanup',
            'description' => 'Purges system audit log entries older than the configured retention period',
            'default_enabled' => 1,
            'default_timezone' => 'UTC',
            'default_schedule_type' => 'daily',
            'default_schedule_interval' => 1,
            'default_schedule_time' => '03:00',
            'default_schedule_weekdays_csv' => null,
            'default_catchup_once' => 1,
            'allowed_schedule_types' => ['daily', 'weekly'],
        ],
        [
            'job_key' => 'audit_api_purge',
            'handler' => \MintyPHP\Module\Audit\Handler\ApiAuditPurgeJobHandler::class,
            'label' => 'API audit log cleanup',
            'description' => 'Purges API audit log entries older than 90 days',
            'default_enabled' => 1,
            'default_timezone' => 'UTC',
            'default_schedule_type' => 'daily',
            'default_schedule_interval' => 1,
            'default_schedule_time' => '03:15',
            'default_schedule_weekdays_csv' => null,
            'default_catchup_once' => 1,
            'allowed_schedule_types' => ['daily', 'weekly'],
        ],
        [
            'job_key' => 'audit_import_purge',
            'handler' => \MintyPHP\Module\Audit\Handler\ImportAuditPurgeJobHandler::class,
            'label' => 'Import audit log cleanup',
            'description' => 'Purges import audit run records older than 90 days',
            'default_enabled' => 1,
            'default_timezone' => 'UTC',
            'default_schedule_type' => 'daily',
            'default_schedule_interval' => 1,
            'default_schedule_time' => '03:30',
            'default_schedule_weekdays_csv' => null,
            'default_catchup_once' => 1,
            'allowed_schedule_types' => ['daily', 'weekly'],
        ],
        [
            'job_key' => 'audit_user_lifecycle_purge',
            'handler' => \MintyPHP\Module\Audit\Handler\UserLifecycleAuditPurgeJobHandler::class,
            'label' => 'User lifecycle audit log cleanup',
            'description' => 'Purges user lifecycle audit entries older than 365 days',
            'default_enabled' => 1,
            'default_timezone' => 'UTC',
            'default_schedule_type' => 'daily',
            'default_schedule_interval' => 1,
            'default_schedule_time' => '03:45',
            'default_schedule_weekdays_csv' => null,
            'default_catchup_once' => 1,
            'allowed_schedule_types' => ['daily', 'weekly'],
        ],
    ],

    'layout_context_providers' => [
        \MintyPHP\Module\Audit\Providers\AuditLayoutProvider::class,
    ],
    'session_providers' => [],

    'event_listeners' => [],
    'search_resources' => [
        \MintyPHP\Module\Audit\Providers\AuditSearchResourceProvider::class,
    ],
    'asset_groups' => [],
    'migrations_path' => 'db/updates',
    'i18n_path' => 'i18n',
];
