import { z } from '@hono/zod-openapi';
import { UserType } from '@d8d/shared-types';

// 人才用户登录请求Schema
export const TalentLoginSchema = z.object({
  identifier: z.string().min(1, '账号不能为空').openapi({
    example: '13800138000',
    description: '手机号、身份证号或残疾证号'
  }),
  password: z.string().min(6, '密码至少6个字符').openapi({
    example: 'password123',
    description: '密码'
  })
});

// 人才基本信息Schema（来自disabled_person表）
export const TalentPersonInfoSchema = z.object({
  id: z.number().int().positive().openapi({
    description: '残疾人ID（person_id）',
    example: 1
  }),
  name: z.string().max(50).openapi({
    description: '姓名',
    example: '张三'
  }),
  gender: z.string().length(1).openapi({
    description: '性别：男/女',
    example: '男'
  }),
  idCard: z.string().max(20).openapi({
    description: '身份证号',
    example: '110101199001011234'
  }),
  disabilityId: z.string().max(50).openapi({
    description: '残疾证号',
    example: 'D12345678'
  }),
  disabilityType: z.string().max(50).openapi({
    description: '残疾类型',
    example: '肢体残疾'
  }),
  disabilityLevel: z.string().max(20).openapi({
    description: '残疾等级',
    example: '一级'
  }),
  phone: z.string().max(20).openapi({
    description: '联系方式',
    example: '13800138000'
  }),
  province: z.string().max(50).openapi({
    description: '省级',
    example: '北京市'
  }),
  city: z.string().max(50).openapi({
    description: '市级',
    example: '北京市'
  }),
  district: z.string().max(50).nullable().openapi({
    description: '区县级',
    example: '朝阳区'
  }),
  detailedAddress: z.string().max(200).nullable().openapi({
    description: '详细地址',
    example: '某某街道123号'
  }),
  jobStatus: z.number().int().openapi({
    description: '在职状态：0-未在职，1-已在职',
    example: 0
  })
});

// 人才用户响应Schema
export const TalentUserResponseSchema = z.object({
  id: z.number().int().positive().openapi({
    description: '用户ID',
    example: 1
  }),
  username: z.string().min(3).max(255).openapi({
    description: '用户名',
    example: 'talent_user'
  }),
  userType: z.nativeEnum(UserType).openapi({
    description: '用户类型',
    example: UserType.TALENT
  }),
  personId: z.number().int().positive().nullable().openapi({
    description: '残疾人ID（关联disabled_person.person_id）',
    example: 1
  }),
  phone: z.string().max(255).nullable().openapi({
    description: '手机号',
    example: '13800138000'
  }),
  nickname: z.string().max(255).nullable().openapi({
    description: '昵称',
    example: '人才用户'
  }),
  name: z.string().max(255).nullable().openapi({
    description: '真实姓名',
    example: '张三'
  }),
  avatarFileId: z.number().int().positive().nullable().openapi({
    description: '头像文件ID',
    example: 1
  }),
  // 关联的残疾人详细信息
  personInfo: TalentPersonInfoSchema.nullable().openapi({
    description: '残疾人详细信息（来自disabled_person表）'
  })
});

// 人才用户登录响应Schema
export const TalentLoginResponseSchema = z.object({
  token: z.string().openapi({
    example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
    description: 'JWT Token'
  }),
  user: TalentUserResponseSchema
});

// 获取人才用户信息响应Schema（复用用户响应Schema）
export const TalentMeResponseSchema = TalentUserResponseSchema;

// 登出成功响应Schema
export const TalentLogoutResponseSchema = z.object({
  message: z.string().openapi({
    example: '登出成功',
    description: '操作结果消息'
  })
});
