import { InternalService } from "@autoplex/microservice";
import { env, secret } from "@autoplex/utils";
import Plex from "../plex";

export default class PlexLibrary extends InternalService
{
	/**
	 * The service name
	 */
	public readonly NAME = "Plex Library";

	/**
	 * A reference to the Plex library
	 */
	protected plex!: Plex;

	/**
	 * Boot the service
	 */
	public async boot() {
		let url       = env("PLEX_URL");
		let token     = await secret(env("PLEX_TOKEN_FILE"));
		let moviesKey = env("PLEX_LIBRARY_MOVIES_KEY");
		let tvKey     = env("PLEX_LIBRARY_TV_KEY");
		this.plex     = new Plex(url, token, moviesKey, tvKey);
	}

	/**
	 * Fetch all IMDB ID's in the Plex movie library
	 */
	public async movieImdbIds() {
		return await this.plex.movies();
	}
}
