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

import { z as zod } from "zod"
import {
	Long,
	UserKarideo,
	UserOut,
	ZodUserKarideo,
	isUserKarideo,
	isUserOut,
} from "../model";

export namespace UserResource {

	/**
	 * Get a specific user data
	 */
	export function get({
			restConfig,
			params,
		}: {
		restConfig: RESTConfig,
		params: {
			id: Long,
		},
	}): Promise<UserKarideo> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/users/{id}",
				requestType: HTTPRequestModel.GET,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
			params,
		}, isUserKarideo);
	};
	/**
	 * Get the user personal data
	 */
	export function getMe({
			restConfig,
		}: {
		restConfig: RESTConfig,
	}): Promise<UserOut> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/users/me",
				requestType: HTTPRequestModel.GET,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
		}, isUserOut);
	};

	export const ZodGetsTypeReturn = zod.array(ZodUserKarideo);
	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 the users
	 */
	export function gets({
			restConfig,
		}: {
		restConfig: RESTConfig,
	}): Promise<GetsTypeReturn> {
		return RESTRequestJson({
			restModel: {
				endPoint: "/users/",
				requestType: HTTPRequestModel.GET,
				accept: HTTPMimeType.JSON,
			},
			restConfig,
		}, isGetsTypeReturn);
	};
}
