import { IpcClientService } from "@autoplex/ipc";
import { Microservice } from "@autoplex/microservice";
import { SOCKET_PATH } from "./constants";
import { IMovieSearchInfo, ITorrentLink } from "./schema";

export class IpcClient<M extends Microservice = Microservice> extends IpcClientService<M>
{
    /**
     * The name of the service
     */
    public readonly NAME = "Torrent Search";

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

	/**
     * Add a torrent to the client
     */
    public async searchMovie(title: string, imdbId: string|null, year: number|null,
                             altTitles: string[] = [], torrentBlacklist: string[] = [])
    {
        let response = await this.request("search_movie", <IMovieSearchInfo> {
            title, imdbId, year, altTitles, torrentBlacklist
        });
        if (response.error) {
            throw new Error("Failed to search for movie torrent");
        }
        return <ITorrentLink|null>response.data;
    }
}
