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

import { z as zod } from "zod"
import {
	Long,
	ObjectId,
	Playlist,
	PlaylistWrite,
	ZodPlaylist,
	isPlaylist,
} from "../model";

export namespace PlaylistResource {

	export function addTrack({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			trackId: Long,
			id: Long,
		},
	}): Promise<Playlist> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/playlist/{id}/track/{trackId}",
				requestType: HTTPRequestModel.POST,
				contentType: HTTPMimeType.MULTIPART,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isPlaylist);
	};
	export function get({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
	}): Promise<Playlist> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/playlist/{id}",
				requestType: HTTPRequestModel.GET,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isPlaylist);
	};

	export const ZodGetsTypeReturn = zod.array(ZodPlaylist);
	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;
		}
	}

	export function gets({
			restConfig,
		}: {
		restConfig: RESTConfig,
	}): Promise<GetsTypeReturn> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/playlist/",
				requestType: HTTPRequestModel.GET,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
		}, isGetsTypeReturn);
	};
	export function patch({
			restConfig,
			params,
			data,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
		data: PlaylistWrite,
	}): Promise<Playlist> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/playlist/{id}",
				requestType: HTTPRequestModel.PATCH,
				contentType: HTTPMimeType.JSON,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
			data,
		}, isPlaylist);
	};
	export function post({
			restConfig,
			data,
		}: {
		restConfig: RESTConfig,
		data: PlaylistWrite,
	}): Promise<Playlist> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/playlist/",
				requestType: HTTPRequestModel.POST,
				contentType: HTTPMimeType.JSON,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			data,
		}, isPlaylist);
	};
	export function remove({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
	}): Promise<void> {
		return RESTRequestVoid({
			restModel: {
				endPoint: "/playlist/{id}",
				requestType: HTTPRequestModel.DELETE,
				contentType: HTTPMimeType.TEXT_PLAIN,
			},
			restConfig,
			params,
		});
	};
	export function removeCover({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			coverId: ObjectId,
			id: Long,
		},
	}): Promise<Playlist> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/playlist/{id}/cover/{coverId}",
				requestType: HTTPRequestModel.DELETE,
				contentType: HTTPMimeType.TEXT_PLAIN,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isPlaylist);
	};
	export function removeTrack({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			trackId: Long,
			id: Long,
		},
	}): Promise<Playlist> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/playlist/{id}/track/{trackId}",
				requestType: HTTPRequestModel.DELETE,
				contentType: HTTPMimeType.TEXT_PLAIN,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isPlaylist);
	};
	export function uploadCover({
			restConfig,
			params,
			data,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
		data: {
			file: File,
		},
	}): Promise<Playlist> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/playlist/{id}/cover",
				requestType: HTTPRequestModel.POST,
				contentType: HTTPMimeType.MULTIPART,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
			data,
		}, isPlaylist);
	};
}
