/**
 * 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,
	ObjectId,
	Track,
	TrackWrite,
	ZodTrack,
	isTrack,
} from "../model";

export namespace TrackResource {

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

	export const ZodGetsTypeReturn = zod.array(ZodTrack);
	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: "/track/",
				requestType: HTTPRequestModel.GET,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
		}, isGetsTypeReturn);
	};
	export function patch({
			restConfig,
			params,
			data,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
		data: TrackWrite,
	}): Promise<Track> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/track/{id}",
				requestType: HTTPRequestModel.PATCH,
				contentType: HTTPMimeType.JSON,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
			data,
		}, isTrack);
	};
	export function post({
			restConfig,
			data,
		}: {
		restConfig: RESTConfig,
		data: TrackWrite,
	}): Promise<Track> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/track/",
				requestType: HTTPRequestModel.POST,
				contentType: HTTPMimeType.JSON,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			data,
		}, isTrack);
	};
	export function remove({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
	}): Promise<void> {
		return RESTRequestVoid({
			restModel: {
				endPoint: "/track/{id}",
				requestType: HTTPRequestModel.DELETE,
				contentType: HTTPMimeType.TEXT_PLAIN,
			},
			restConfig,
			params,
		});
	};
	export function removeCover({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			coverId: ObjectId,
			id: Long,
		},
	}): Promise<Track> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/track/{id}/cover/{coverId}",
				requestType: HTTPRequestModel.DELETE,
				contentType: HTTPMimeType.TEXT_PLAIN,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isTrack);
	};
	export function removeTrack({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			artistId: Long,
			id: Long,
		},
	}): Promise<Track> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/track/{id}/artist/{trackId}",
				requestType: HTTPRequestModel.DELETE,
				contentType: HTTPMimeType.TEXT_PLAIN,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isTrack);
	};
	export function uploadCover({
			restConfig,
			params,
			data,
			callbacks,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
		data: {
			file: File,
			uri: string,
		},
		callbacks?: RESTCallbacks,
	}): Promise<Track> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/track/{id}/cover",
				requestType: HTTPRequestModel.POST,
				contentType: HTTPMimeType.MULTIPART,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
			data,
			callbacks,
		}, isTrack);
	};
	export function uploadTrack({
			restConfig,
			data,
			callbacks,
		}: {
		restConfig: RESTConfig,
		data: {
			file: File,
			trackId?: Long,
			genderId?: Long,
			albumId?: Long,
			artistId?: Long,
			title: string,
		},
		callbacks?: RESTCallbacks,
	}): Promise<Track> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/track/upload/",
				requestType: HTTPRequestModel.POST,
				contentType: HTTPMimeType.MULTIPART,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			data,
			callbacks,
		}, isTrack);
	};
}
