import { WebSocketServerService } from "@autoplex/websocket-server";
import { WebSocketMethod } from "@autoplex-api/interface";
import { IpcClient as ManagerIpc } from "@autoplex-api/manager";
import Application from "../Application";

export default class WebSocketServer extends WebSocketServerService<Application>
{
	/**
	 * The name of the service
	 */
	public readonly NAME = "WebSocket Server";

	/**
	 * Reference to the Manager IPC service
	 */
	protected manager!: ManagerIpc;

	/**
	 * Boot the service
	 */
	public override async boot() {
		super.boot();
		this.manager = this.app.service<ManagerIpc>("Manager");
	}

	/**
	 * The application key used for authentication
	 */
	protected get appKey() {
		return Application.instance().APP_KEY;
	}

	/**
	 * Install the websocket request methods
	 */
	protected override installMethods() {
		this.installMethod(WebSocketMethod.TicketProgress, this.ticketProgress.bind(this));
	}

	// Methods -------------------------------------------------------------------------------------

	/**
	 * Get the ticket progress
	 */
	protected async ticketProgress(ticketIds: number[]) {
		// let result: { [ticketId: number]: { plexLink?: string, progress?: number } } = {};
		let response = await this.manager.getMovieTicketStates(ticketIds);
		return response;
	}
}
