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

extendZodWithOpenApi(z);

// Enums
const EntityStatusEnum = z.enum(['active', 'inactive']);

// Request body schemas for validation and OpenAPI documentation
export const BedCreateBodySchema = z
	.object({
		room_id: uuidSchema.openapi({ example: 'aa0e8400-e29b-41d4-a716-446655440001' }),
		name: z.string().min(1).max(200).openapi({ example: 'Giường 1' }),
		code: z.string().min(1).max(50).openapi({ example: 'G-001' }),
		status: EntityStatusEnum.optional().default('active').openapi({ example: 'active' }),
	})
	.openapi('BedCreateBody');

export const BedUpdateBodySchema = z
	.object({
		room_id: uuidSchema.optional().openapi({ example: 'aa0e8400-e29b-41d4-a716-446655440001' }),
		name: z.string().min(1).max(200).optional().openapi({ example: 'Giường 1' }),
		code: z.string().min(1).max(50).optional().openapi({ example: 'G-001' }),
		status: EntityStatusEnum.optional().openapi({ example: 'active' }),
	})
	.openapi('BedUpdateBody');

// Response schemas for OpenAPI documentation
export const BedSchema = z
	.object({
		id: uuidSchema.openapi({ example: 'bb0e8400-e29b-41d4-a716-446655440001' }),
		room_id: uuidSchema.openapi({ example: 'aa0e8400-e29b-41d4-a716-446655440001' }),
		name: z.string().openapi({ example: 'Giường 1' }),
		code: z.string().openapi({ example: 'G-001' }),
		status: EntityStatusEnum.openapi({ example: 'active' }),
		created_at: z.iso.datetime().openapi({ example: '2024-01-15T08:30:00Z' }),
		updated_at: z.iso.datetime().nullable().openapi({ example: '2024-01-20T10:00:00Z' }),
		deleted_at: z.iso.datetime().nullable().openapi({ example: null }),
	})
	.openapi('Bed');

export const BedListDataSchema = z
	.object({
		count: z.number().openapi({ example: 10 }),
		rows: z.array(BedSchema),
		page: z.number().openapi({ example: 1 }),
		pageSize: z.number().openapi({ example: 10 }),
	})
	.openapi('BedListData');

export const BedResponseSchema = ApiResponseSchema(BedSchema).openapi('BedResponse');

export const BedListResponseSchema = ApiResponseSchema(BedListDataSchema).openapi('BedListResponse');
