import { z } from 'zod';
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
import { ApiResponseSchema } from '#contracts/shared';

extendZodWithOpenApi(z);

// Request body schemas for validation and OpenAPI documentation
export const ContractTypeCreateBodySchema = z.object({
	code: z.string().min(1).max(200), // TODO: adjust validation rules (type, min, max, etc.)
	name_vi: z.string().min(1).max(200), // TODO: adjust validation rules (type, min, max, etc.)
	name_en: z.string().min(1).max(200), // TODO: adjust validation rules (type, min, max, etc.)
	description: z.string().min(1).max(200), // TODO: adjust validation rules (type, min, max, etc.)
}).openapi('ContractTypeCreateBody');

export const ContractTypeUpdateBodySchema = z.object({
	code: z.string().min(1).max(200).optional(), // TODO: adjust validation rules (type, min, max, etc.)
	name_vi: z.string().min(1).max(200).optional(), // TODO: adjust validation rules (type, min, max, etc.)
	name_en: z.string().min(1).max(200).optional(), // TODO: adjust validation rules (type, min, max, etc.)
	description: z.string().min(1).max(200).optional(), // TODO: adjust validation rules (type, min, max, etc.)
}).openapi('ContractTypeUpdateBody');

// Response schemas for OpenAPI documentation
export const ContractTypeSchema = z.object({
	id: z.uuid(),
	code: z.string().min(1).max(200), // TODO: adjust validation rules (type, min, max, etc.)
	name_vi: z.string().min(1).max(200), // TODO: adjust validation rules (type, min, max, etc.)
	name_en: z.string().min(1).max(200), // TODO: adjust validation rules (type, min, max, etc.)
	description: z.string().min(1).max(200), // TODO: adjust validation rules (type, min, max, etc.)
	created_at: z.iso.datetime(),
	updated_at: z.iso.datetime().nullable(),
	deleted_at: z.iso.datetime().nullable(),
}).openapi('ContractType');

export const ContractTypeListDataSchema = z.object({
	count: z.number(),
	rows: z.array(ContractTypeSchema),
	page: z.number(),
	pageSize: z.number(),
}).openapi('ContractTypeListData');

export const ContractTypeResponseSchema = ApiResponseSchema(ContractTypeSchema).openapi('ContractTypeResponse');

export const ContractTypeListResponseSchema = ApiResponseSchema(ContractTypeListDataSchema).openapi('ContractTypeListResponse');
