/**
 * Interface of the server (auto-generated code)
 */
import {
	HTTPMimeType,
	HTTPRequestModel,
	RESTCallbacks,
	RESTConfig,
	RESTRequestJson,
	RESTRequestVoid,
} from "../rest-tools";

import { z as zod } from "zod"
import {
	Long,
	Media,
	MediaWrite,
	UUID,
	ZodMedia,
	isMedia,
} from "../model";

export namespace MediaResource {

	/**
	 * Get a specific Media with his ID
	 */
	export function get({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
	}): Promise<Media> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/media/{id}",
				requestType: HTTPRequestModel.GET,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isMedia);
	};

	export const ZodGetsTypeReturn = zod.array(ZodMedia);
	export type GetsTypeReturn = zod.infer<typeof ZodGetsTypeReturn>;
	
	export function isGetsTypeReturn(data: any): data is GetsTypeReturn {
		try {
			ZodGetsTypeReturn.parse(data);
			return true;
		} catch (e: any) {
			console.log(`Fail to parse data type='ZodGetsTypeReturn' error=${e}`);
			return false;
		}
	}

	/**
	 * Get all Media
	 */
	export function gets({
			restConfig,
		}: {
		restConfig: RESTConfig,
	}): Promise<GetsTypeReturn> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/media/",
				requestType: HTTPRequestModel.GET,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
		}, isGetsTypeReturn);
	};
	/**
	 * Modify a specific Media
	 */
	export function patch({
			restConfig,
			params,
			data,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
		data: MediaWrite,
	}): Promise<Media> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/media/{id}",
				requestType: HTTPRequestModel.PATCH,
				contentType: HTTPMimeType.JSON,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
			data,
		}, isMedia);
	};
	/**
	 * Remove a specific Media
	 */
	export function remove({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
	}): Promise<void> {
		return RESTRequestVoid({
			restModel: {
				endPoint: "/media/{id}",
				requestType: HTTPRequestModel.DELETE,
				contentType: HTTPMimeType.TEXT_PLAIN,
			},
			restConfig,
			params,
		});
	};
	/**
	 * Remove a specific cover of a media
	 */
	export function removeCover({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			coverId: UUID,
			id: Long,
		},
	}): Promise<Media> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/media/{id}/cover/{coverId}",
				requestType: HTTPRequestModel.DELETE,
				contentType: HTTPMimeType.TEXT_PLAIN,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isMedia);
	};
	/**
	 * Upload a new season cover media
	 */
	export function uploadCover({
			restConfig,
			params,
			data,
			callbacks,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
		data: {
			file: File,
		},
		callbacks?: RESTCallbacks,
	}): Promise<Media> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/media/{id}/cover",
				requestType: HTTPRequestModel.POST,
				contentType: HTTPMimeType.MULTIPART,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
			data,
			callbacks,
		}, isMedia);
	};
	/**
	 * Create a new Media
	 */
	export function uploadFile({
			restConfig,
			data,
			callbacks,
		}: {
		restConfig: RESTConfig,
		data: {
			fileName: string,
			file: File,
			series: string,
			universe: string,
			season: string,
			episode: string,
			typeId: string,
			title: string,
		},
		callbacks?: RESTCallbacks,
	}): Promise<Media> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/media/",
				requestType: HTTPRequestModel.POST,
				contentType: HTTPMimeType.MULTIPART,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			data,
			callbacks,
		}, isMedia);
	};
}
