import { MovieTicket } from "@autoplex/database";
import Provider, { MediaType } from "../Provider";
import Torrent from "../../Torrent";
import { search, Sort } from "./search";


export default class TorrentGalaxy extends Provider
{
	/**
	 * Indicate that this provider provides movies
	 */
	public static readonly PROVIDES = MediaType.Movies;

	/**
	 * Search for a movie
	 */
	public async searchMovie(movie: MovieTicket) {
		if (movie.imdbId === null) {
			return [];
		}
		let torrents = await search(movie.imdbId, undefined, Sort.Seeders);
		return torrents.torrents.map(torrent => new Torrent(
			movie,
			torrent.name,
			torrent.size,
			torrent.seeders,
			torrent.magnet
		));
	}
}
