import ApiRequestManager from "./ApiRequestManager";
import * as Schema from "./schema";

export default class TheMovieDb
{
	/**
	 * The APi request manager
	 */
	protected requestManager!: ApiRequestManager;

	/**
	 * Create a new TheMovieDB API instance
	 */
	public constructor(apiKey: string) {
		this.requestManager = new ApiRequestManager(apiKey);
	}

	/**
	 * Get the API configuration details
	 */
	public async configuration() {
		return await this.requestManager.get("/configuration");
	}

	/**
	 * Search for a movie
	 */
	public async searchMovie(query: string, year?: number, page?: number) {
		return await this.requestManager.get<Schema.IPaginatedResponse<Schema.IMovieSearchResult>>("/search/movie", { query, year });
	}

	/**
	 * Get the details of a movie
	 */
	public async movie(id: number) {
		return await this.requestManager.get<Schema.IMovieDetails>(`/movie/${id}`);
	}

	/**
	 * Find a movie given an external ID
	 */
	public async findMovie(id: string, externalSource: Schema.ExternalSource) {
		return await this.requestManager.get<Schema.IFindResult>(`/find/${id}`, { external_source: externalSource });
	}
}
