import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm';

@Entity('users')
export class User {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ length: 20, nullable: true, comment: '手机号' })
  @Index()
  phone: string;

  @Column({ length: 255, nullable: true, select: false, comment: '密码' })
  password: string;

  @Column({ name: 'wechat_openid', length: 100, nullable: true, comment: '微信openid' })
  @Index()
  wechatOpenid: string;

  @Column({ name: 'wechat_unionid', length: 100, nullable: true, comment: '微信unionid' })
  @Index()
  wechatUnionid: string;

  @Column({ length: 50, default: '', comment: '昵称' })
  nickname: string;

  @Column({ length: 500, default: '', comment: '头像URL' })
  avatar: string;

  @Column({ type: 'tinyint', unsigned: true, default: 0, comment: '性别 0-未知 1-男 2-女' })
  gender: number;

  @Column({ name: 'real_name', length: 50, nullable: true, comment: '真实姓名' })
  realName: string;

  @Column({ name: 'id_card', length: 255, nullable: true, select: false, comment: '身份证号' })
  idCard: string;

  @Column({ name: 'is_verified', type: 'boolean', default: false, comment: '是否实名认证' })
  isVerified: boolean;

  @Column({ name: 'verified_at', type: 'datetime', nullable: true, comment: '实名认证时间' })
  verifiedAt: Date;

  @Index()
  @Column({ type: 'enum', enum: ['active', 'frozen', 'deleted'], default: 'active', comment: '状态' })
  status: 'active' | 'frozen' | 'deleted';

  @Column({ name: 'last_login_at', type: 'datetime', nullable: true, comment: '最后登录时间' })
  lastLoginAt: Date;

  @CreateDateColumn({ name: 'created_at', comment: '创建时间' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', comment: '更新时间' })
  updatedAt: Date;
}
