import { z } from '@hono/zod-openapi';

// 订单商品项DTO
export const OrderItemDto = z.object({
  id: z.number().int().positive('商品ID必须是正整数').openapi({
    description: '商品ID',
    example: 1
  }),
  num: z.number().int().min(1, '购买数量必须大于0').openapi({
    description: '购买数量',
    example: 2
  })
});

// 创建订单请求DTO
export const CreateOrderRequestDto = z.object({
  addressId: z.number().int().positive('收货地址ID必须是正整数').optional().openapi({
    description: '收货地址ID',
    example: 1
  }),
  productOwn: z.string().min(1, '商品所属方不能为空').max(50, '商品所属方最多50个字符').openapi({
    description: '商品所属方（如：自营、第三方等）',
    example: '自营'
  }),
  consumeFrom: z.string().min(1, '消费来源不能为空').max(50, '消费来源最多50个字符').openapi({
    description: '消费来源（如：积分兑换、礼券兑换等）',
    example: '积分兑换'
  }),
  products: z.array(OrderItemDto).min(1, '商品列表不能为空').openapi({
    description: '商品列表',
    example: [{ id: 1, num: 2 }, { id: 3, num: 1 }]
  })
});

// 创建订单响应DTO
export const CreateOrderResponseDto = z.object({
  success: z.boolean().openapi({
    description: '是否成功',
    example: true
  }),
  orderId: z.number().int().positive().openapi({
    description: '订单ID',
    example: 1001
  }),
  orderNo: z.string().openapi({
    description: '订单号',
    example: 'ORD20240101123456'
  }),
  amount: z.coerce.number().openapi({
    description: '订单总金额',
    example: 199.98
  }),
  payAmount: z.coerce.number().openapi({
    description: '实际支付金额',
    example: 199.98
  }),
  message: z.string().openapi({
    description: '提示信息',
    example: '订单创建成功'
  })
});

// 导出类型
export type CreateOrderRequest = z.infer<typeof CreateOrderRequestDto>;
export type CreateOrderResponse = z.infer<typeof CreateOrderResponseDto>;
export type OrderItem = z.infer<typeof OrderItemDto>;