import { IMovieSearchInfo, SOCKET_PATH } from "@autoplex-api/torrent-search";
import { Microservice } from "@autoplex/microservice";
import { IpcServerService } from "@autoplex/ipc";
import TorrentSearch from "./TorrentSearch";

export default class IpcInterface extends IpcServerService
{
    /**
     * The service name
     */
    public readonly NAME = "IPC";

    /**
     * The path to the socket file
     */
    public readonly SOCKET_PATH = SOCKET_PATH;

    /**
     * The torrent search service
     */
    protected search!: TorrentSearch;

    /**
     * Link the IPC service to other required internal services
     */
    public link(app: Microservice) {
        this.search = app.service<TorrentSearch>("Torrent Search");
    }

    /**
     * Install the the event handlers
     */
    protected installMessageHandlers() {
        this.addMessageHandler("search_movie", this.searchMovie);
    }

    // Interface Methods ---------------------------------------------------------------------------

	/**
	 * Invoked when a new Movie ticket has been created
	 */
	protected async searchMovie(movie: IMovieSearchInfo) {
        return await this.search.searchMovie(movie);
	}
}
