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

// 渠道实体Schema
export const ChannelSchema = z.object({
  id: z.number().int().positive().openapi({
    description: '渠道ID',
    example: 1
  }),
  channelName: z.string().max(100).openapi({
    description: '渠道名称',
    example: '微信小程序'
  }),
  channelType: z.string().max(50).openapi({
    description: '渠道类型',
    example: '小程序'
  }),
  contactPerson: z.string().max(50).openapi({
    description: '联系人',
    example: '张三'
  }),
  contactPhone: z.string().max(20).openapi({
    description: '联系电话',
    example: '13800138000'
  }),
  description: z.string().nullable().optional().openapi({
    description: '描述',
    example: '微信小程序渠道'
  }),
  status: z.number().int().min(0).max(1).default(1).openapi({
    description: '状态：1-正常，0-禁用',
    example: 1
  }),
  createTime: z.coerce.date().openapi({
    description: '创建时间',
    example: '2024-01-01T00:00:00Z'
  }),
  updateTime: z.coerce.date().openapi({
    description: '更新时间',
    example: '2024-01-01T00:00:00Z'
  })
});

// 创建渠道DTO
export const CreateChannelSchema = z.object({
  channelName: z.string().min(1).max(100).openapi({
    description: '渠道名称',
    example: '微信小程序'
  }),
  channelType: z.string().max(50).optional().openapi({
    description: '渠道类型',
    example: '小程序'
  }),
  contactPerson: z.string().max(50).optional().openapi({
    description: '联系人',
    example: '张三'
  }),
  contactPhone: z.string().max(20).optional().openapi({
    description: '联系电话',
    example: '13800138000'
  }),
  description: z.string().optional().openapi({
    description: '描述',
    example: '微信小程序渠道'
  })
});

// 更新渠道DTO
export const UpdateChannelSchema = z.object({
  id: z.number().int().positive().openapi({
    description: '渠道ID',
    example: 1
  }),
  channelName: z.string().min(1).max(100).optional().openapi({
    description: '渠道名称',
    example: '微信小程序'
  }),
  channelType: z.string().max(50).optional().openapi({
    description: '渠道类型',
    example: '小程序'
  }),
  contactPerson: z.string().max(50).optional().openapi({
    description: '联系人',
    example: '张三'
  }),
  contactPhone: z.string().max(20).optional().openapi({
    description: '联系电话',
    example: '13800138000'
  }),
  description: z.string().optional().openapi({
    description: '描述',
    example: '微信小程序渠道'
  })
});

// 删除渠道DTO
export const DeleteChannelSchema = z.object({
  id: z.number().int().positive().openapi({
    description: '渠道ID',
    example: 1
  })
});

// 分页查询参数Schema
export const PaginationQuerySchema = z.object({
  skip: z.coerce.number().int().min(0).default(0).optional().openapi({
    description: '跳过记录数',
    example: 0
  }),
  take: z.coerce.number().int().min(1).max(100).default(10).optional().openapi({
    description: '获取记录数',
    example: 10
  })
});

// 搜索渠道参数Schema
export const SearchChannelQuerySchema = PaginationQuerySchema.extend({
  name: z.string().min(1).openapi({
    description: '搜索关键词',
    example: '微信'
  })
});

// 类型定义
export type Channel = z.infer<typeof ChannelSchema>;
export type CreateChannelDto = z.infer<typeof CreateChannelSchema>;
export type UpdateChannelDto = z.infer<typeof UpdateChannelSchema>;
export type DeleteChannelDto = z.infer<typeof DeleteChannelSchema>;
export type PaginationQuery = z.infer<typeof PaginationQuerySchema>;
export type SearchChannelQuery = z.infer<typeof SearchChannelQuerySchema>;