/**
 * Interface of the server (auto-generated code)
 */
import { z as zod } from "zod";

import {ZodLong} from "./long";
import {ZodObjectId} from "./object-id";
import {ZodOIDGenericDataSoftDelete, ZodOIDGenericDataSoftDeleteWrite } from "./oid-generic-data-soft-delete";

export const ZodData = ZodOIDGenericDataSoftDelete.extend({
	/**
	 * Sha512 of the data
	 */
	sha512: zod.string().max(512),
	/**
	 * Mime -type of the media
	 */
	mimeType: zod.string().max(512),
	/**
	 * Size in Byte of the data
	 */
	size: ZodLong,
	/**
	 * Unique ObjectID of the object
	 */
	oid: ZodObjectId.readonly(),

});

export type Data = zod.infer<typeof ZodData>;

export function isData(data: any): data is Data {
	try {
		ZodData.parse(data);
		return true;
	} catch (e: any) {
		console.log(`Fail to parse data type='ZodData' error=${e}`);
		return false;
	}
}
export const ZodDataWrite = ZodOIDGenericDataSoftDeleteWrite.extend({
	/**
	 * Sha512 of the data
	 */
	sha512: zod.string().max(512).optional(),
	/**
	 * Mime -type of the media
	 */
	mimeType: zod.string().max(512).optional(),
	/**
	 * Size in Byte of the data
	 */
	size: ZodLong.optional(),

});

export type DataWrite = zod.infer<typeof ZodDataWrite>;

export function isDataWrite(data: any): data is DataWrite {
	try {
		ZodDataWrite.parse(data);
		return true;
	} catch (e: any) {
		console.log(`Fail to parse data type='ZodDataWrite' error=${e}`);
		return false;
	}
}
