export type NotifyType = 'info' | 'success' | 'warning' | 'error';

/**
 * A button shown on an action toast. When clicked, `event` is fired as a
 * remote event on the server with the supplied `args`.
 */
export interface NotifyAction {
    label: string;
    event: string;
    args?: (string | number | boolean)[];
}

/**
 * Server-side helper for sending toast notifications to players via the
 * custom overlay notify component. Replaces raw player.notify() calls.
 *
 * Standard toasts:
 *   NotifySystem.Info(player, 'Heading to depot...')
 *   NotifySystem.Success(player, 'Package delivered!')
 *   NotifySystem.Warning(player, 'Van not at depot yet.')
 *   NotifySystem.Error(player, 'You must be in a company vehicle.')
 *
 * Action toasts (persistent, with buttons):
 *   NotifySystem.Action(player, 'ride_1', 'Taxi request 1.2km away', 'info', [
 *       { label: 'Accept', event: 'taxiDuty:accept', args: [1] },
 *       { label: 'Decline', event: 'taxiDuty:decline', args: [1] },
 *   ]);
 *
 * Dismiss a specific action toast by key:
 *   NotifySystem.Dismiss(player, 'ride_1');
 */
export class NotifySystem {
    static Show(player: PlayerMp, message: string, type: NotifyType = 'info', duration = 5000): void {
        player.call('notify:show', [message, type, duration]);
    }

    static Info(player: PlayerMp, message: string, duration?: number): void {
        this.Show(player, message, 'info', duration);
    }

    static Success(player: PlayerMp, message: string, duration?: number): void {
        this.Show(player, message, 'success', duration);
    }

    static Warning(player: PlayerMp, message: string, duration?: number): void {
        this.Show(player, message, 'warning', duration);
    }

    static Error(player: PlayerMp, message: string, duration?: number): void {
        this.Show(player, message, 'error', duration);
    }

    /**
     * Show a persistent toast with action buttons. The toast stays on screen
     * until the player clicks a button, closes it manually, or the server
     * calls Dismiss() with the same key.
     */
    static Action(player: PlayerMp, key: string, message: string, type: NotifyType = 'info', actions: NotifyAction[]): void {
        player.call('notify:action', [key, message, type, JSON.stringify(actions)]);
    }

    /**
     * Remove a specific action toast from a player's screen by key.
     * Safe to call even if the toast has already been dismissed.
     */
    static Dismiss(player: PlayerMp, key: string): void {
        player.call('notify:dismiss', [key]);
    }
}
