import { IMovieSearchInfo } from "@autoplex-api/torrent-search";
import Provider, { MediaType } from "../Provider";
import { search } from "./search";
import { Sort } from "./schema";

export default class TorrentGalaxy extends Provider
{
	/**
	 * The torrent provider name
	 */
	public readonly NAME = "Torrent Galaxy";

	/**
	 * Indicate that this provider provides movies
	 */
	public readonly PROVIDES = MediaType.Movies;

	/**
	 * Throttle the requests
	 */
	protected readonly THROTTLE = 3000;

	/**
	 * Search for a movie
	 */
	public async searchMovieImdb(imdbId: string, movie: IMovieSearchInfo) {
		let torrents = await search(imdbId, undefined, Sort.Seeders);
		return torrents.torrents.map(torrent => this.createTorrent(
			movie, torrent.name, torrent.size,torrent.seeders, torrent.magnet
		));
	}
}
