/**
 * AniWorld - Constants Module
 *
 * Shared constants, API endpoints, and configuration values
 * used across all JavaScript modules.
 *
 * Dependencies: None (must be loaded first)
 */

var AniWorld = window.AniWorld || {};

AniWorld.Constants = (function() {
    'use strict';

    // API Endpoints
    const API = {
        // Auth endpoints
        AUTH_STATUS: '/api/auth/status',
        AUTH_LOGIN: '/api/auth/login',
        AUTH_LOGOUT: '/api/auth/logout',

        // Anime endpoints
        ANIME_LIST: '/api/anime',
        ANIME_SEARCH: '/api/anime/search',
        ANIME_ADD: '/api/anime/add',
        ANIME_RESCAN: '/api/anime/rescan',
        ANIME_STATUS: '/api/anime/status',
        ANIME_SCAN_STATUS: '/api/anime/scan/status',
        ANIME_LOADING_STATUS: '/api/anime',  // + /{key}/loading-status

        // Queue endpoints
        QUEUE_STATUS: '/api/queue/status',
        QUEUE_ADD: '/api/queue/add',
        QUEUE_START: '/api/queue/start',
        QUEUE_STOP: '/api/queue/stop',
        QUEUE_RETRY: '/api/queue/retry',
        QUEUE_REMOVE: '/api/queue',  // + /{id}
        QUEUE_COMPLETED: '/api/queue/completed',
        QUEUE_FAILED: '/api/queue/failed',
        QUEUE_PENDING: '/api/queue/pending',

        // Config endpoints
        CONFIG: '/api/config',
        CONFIG_DIRECTORY: '/api/config/directory',
        CONFIG_SECTION: '/api/config/section',  // + /{section}
        CONFIG_BACKUP: '/api/config/backup',
        CONFIG_BACKUPS: '/api/config/backups',
        CONFIG_VALIDATE: '/api/config/validate',
        CONFIG_RESET: '/api/config/reset',

        // Scheduler endpoints
        SCHEDULER_CONFIG: '/api/scheduler/config',
        SCHEDULER_TRIGGER: '/api/scheduler/trigger-rescan',

        // Logging endpoints
        LOGGING_CONFIG: '/api/logging/config',
        LOGGING_FILES: '/api/logging/files',
        LOGGING_CLEANUP: '/api/logging/cleanup',
        LOGGING_TEST: '/api/logging/test',

        // Diagnostics
        DIAGNOSTICS_NETWORK: '/api/diagnostics/network'
    };

    // Local Storage Keys
    const STORAGE_KEYS = {
        ACCESS_TOKEN: 'access_token',
        TOKEN_EXPIRES_AT: 'token_expires_at',
        THEME: 'theme'
    };

    // Default Values
    const DEFAULTS = {
        THEME: 'light',
        TOAST_DURATION: 5000,
        SCAN_AUTO_DISMISS: 3000,
        REFRESH_INTERVAL: 2000
    };

    // WebSocket Rooms
    const WS_ROOMS = {
        DOWNLOADS: 'downloads',
        QUEUE: 'queue',
        SCAN: 'scan',
        SYSTEM: 'system',
        ERRORS: 'errors'
    };

    // WebSocket Events
    const WS_EVENTS = {
        // Connection
        CONNECTED: 'connected',
        CONNECT: 'connect',
        DISCONNECT: 'disconnect',

        // Scan events
        SCAN_STARTED: 'scan_started',
        SCAN_PROGRESS: 'scan_progress',
        SCAN_COMPLETED: 'scan_completed',
        SCAN_COMPLETE: 'scan_complete',
        SCAN_ERROR: 'scan_error',
        SCAN_FAILED: 'scan_failed',

        // Series events
        SERIES_UPDATED: 'series_updated',
        SERIES_LOADING_UPDATE: 'series_loading_update',

        // Scheduled scan events
        SCHEDULED_RESCAN_STARTED: 'scheduled_rescan_started',
        SCHEDULED_RESCAN_COMPLETED: 'scheduled_rescan_completed',
        SCHEDULED_RESCAN_ERROR: 'scheduled_rescan_error',
        SCHEDULED_RESCAN_SKIPPED: 'scheduled_rescan_skipped',

        // Download events
        DOWNLOAD_STARTED: 'download_started',
        DOWNLOAD_PROGRESS: 'download_progress',
        DOWNLOAD_COMPLETED: 'download_completed',
        DOWNLOAD_COMPLETE: 'download_complete',
        DOWNLOAD_ERROR: 'download_error',
        DOWNLOAD_FAILED: 'download_failed',
        DOWNLOAD_PAUSED: 'download_paused',
        DOWNLOAD_RESUMED: 'download_resumed',
        DOWNLOAD_CANCELLED: 'download_cancelled',
        DOWNLOAD_STOPPED: 'download_stopped',
        DOWNLOAD_STOP_REQUESTED: 'download_stop_requested',

        // Queue events
        QUEUE_UPDATED: 'queue_updated',
        QUEUE_STATUS: 'queue_status',
        QUEUE_STARTED: 'queue_started',
        QUEUE_STOPPED: 'queue_stopped',
        QUEUE_PAUSED: 'queue_paused',
        QUEUE_RESUMED: 'queue_resumed',
        QUEUE_COMPLETED: 'queue_completed',
        DOWNLOAD_QUEUE_COMPLETED: 'download_queue_completed',
        DOWNLOAD_QUEUE_UPDATE: 'download_queue_update',
        DOWNLOAD_EPISODE_UPDATE: 'download_episode_update',
        DOWNLOAD_SERIES_COMPLETED: 'download_series_completed',

        // Auto download
        AUTO_DOWNLOAD_STARTED: 'auto_download_started',
        AUTO_DOWNLOAD_ERROR: 'auto_download_error'
    };

    // Public API
    return {
        API: API,
        STORAGE_KEYS: STORAGE_KEYS,
        DEFAULTS: DEFAULTS,
        WS_ROOMS: WS_ROOMS,
        WS_EVENTS: WS_EVENTS
    };
})();
