import { z } from '@hono/zod-openapi';
import { ErrorSchema } from '@d8d/shared-utils/schema/error';

/**
 * 个人信息响应Schema
 */
export const PersonalInfoResponseSchema = z.object({
  name: z.string().openapi({
    description: '姓名',
    example: '张三'
  }),
  gender: z.string().openapi({
    description: '性别：男/女',
    example: '男'
  }),
  idCard: z.string().openapi({
    description: '身份证号',
    example: '110101199001011234'
  }),
  disabilityId: z.string().openapi({
    description: '残疾证号',
    example: 'D12345678'
  }),
  disabilityType: z.string().openapi({
    description: '残疾类型',
    example: '肢体残疾'
  }),
  disabilityLevel: z.string().openapi({
    description: '残疾等级',
    example: '一级'
  }),
  phone: z.string().openapi({
    description: '联系方式',
    example: '13800138000'
  }),
  province: z.string().openapi({
    description: '省级',
    example: '北京市'
  }),
  city: z.string().openapi({
    description: '市级',
    example: '北京市'
  }),
  district: z.string().nullable().openapi({
    description: '区县级',
    example: '朝阳区'
  }),
  detailedAddress: z.string().nullable().openapi({
    description: '详细地址',
    example: '某某街道123号'
  }),
  birthDate: z.coerce.date<string>().nullable().transform(val => val ? val.toISOString().split('T')[0] : null).openapi({
    description: '出生日期（ISO 8601格式）',
    example: '1990-01-01'
  }),
  idAddress: z.string().openapi({
    description: '身份证地址',
    example: '北京市朝阳区某某街道123号'
  }),
  idValidDate: z.coerce.date<string>().nullable().transform(val => val ? val.toISOString().split('T')[0] : null).openapi({
    description: '身份证有效期（ISO 8601格式）',
    example: '2030-01-01'
  }),
  disabilityValidDate: z.coerce.date<string>().nullable().transform(val => val ? val.toISOString().split('T')[0] : null).openapi({
    description: '残疾证有效期（ISO 8601格式）',
    example: '2025-12-31'
  }),
  canDirectContact: z.number().openapi({
    description: '是否可直接联系：1-是，0-否',
    example: 1
  }),
  isMarried: z.number().nullable().openapi({
    description: '是否已婚：1-是，0-否',
    example: 0
  }),
  nation: z.string().nullable().openapi({
    description: '民族',
    example: '汉族'
  }),
  jobStatus: z.number().openapi({
    description: '在职状态：0-未在职，1-已在职',
    example: 0
  }),
  specificDisability: z.string().nullable().openapi({
    description: '具体残疾部位和情况',
    example: '左腿小腿截肢'
  })
});

/**
 * 银行卡信息Schema（包含卡号脱敏）
 */
export const BankCardInfoSchema = z.object({
  id: z.number().openapi({
    description: '银行卡ID',
    example: 1
  }),
  subBankName: z.string().openapi({
    description: '发卡支行',
    example: '中国工商银行北京分行朝阳支行'
  }),
  bankName: z.string().nullable().openapi({
    description: '银行名称',
    example: '中国工商银行'
  }),
  cardNumber: z.string().openapi({
    description: '卡号（脱敏：前4位+****+后4位）',
    example: '6222****0123'
  }),
  cardholderName: z.string().openapi({
    description: '持卡人姓名',
    example: '张三'
  }),
  cardType: z.string().nullable().openapi({
    description: '银行卡类型：一类卡/二类卡',
    example: '一类卡'
  }),
  isDefault: z.number().openapi({
    description: '是否默认：1-是，0-否',
    example: 1
  }),
  fileUrl: z.string().nullable().openapi({
    description: '银行卡照片URL',
    example: 'https://example.com/files/bank-card-1.jpg'
  })
});

/**
 * 银行卡列表响应Schema
 */
export const BankCardsResponseSchema = z.object({
  data: z.array(BankCardInfoSchema).openapi({
    description: '银行卡列表'
  }),
  total: z.number().openapi({
    description: '银行卡总数',
    example: 2
  })
});

/**
 * 证件照片信息Schema
 */
export const PhotoInfoSchema = z.object({
  id: z.number().openapi({
    description: '照片ID',
    example: 1
  }),
  photoType: z.string().openapi({
    description: '照片类型',
    example: '身份证'
  }),
  fileUrl: z.string().nullable().openapi({
    description: '照片文件URL',
    example: 'https://example.com/files/id-card-1.jpg'
  }),
  fileName: z.string().nullable().openapi({
    description: '文件名',
    example: '身份证正面.jpg'
  }),
  uploadTime: z.string().openapi({
    description: '上传时间（ISO 8601格式）',
    example: '2024-01-01T10:30:00Z'
  }),
  canDownload: z.number().openapi({
    description: '是否可下载：1-是，0-否',
    example: 1
  })
});

/**
 * 证件照片列表响应Schema
 */
export const PhotosResponseSchema = z.object({
  data: z.array(PhotoInfoSchema).openapi({
    description: '证件照片列表'
  }),
  total: z.number().openapi({
    description: '照片总数',
    example: 5
  })
});

/**
 * 证件照片查询参数Schema
 */
export const PhotosQuerySchema = z.object({
  photoType: z.string().optional().openapi({
    description: '按照片类型过滤（可选）',
    example: '身份证'
  }),
  skip: z.coerce.number().int().min(0).default(0).openapi({
    description: '跳过记录数',
    example: 0
  }),
  take: z.coerce.number().int().min(1).max(100).default(10).openapi({
    description: '获取记录数（1-100）',
    example: 10
  })
});

/**
 * 错误响应Schema（复用）
 */
export { ErrorSchema };
