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

@Entity('user_contacts')
@Index('idx_user_contacts_tenant', ['tenantId'])
@Index('idx_user_contacts_user', ['tenantId', 'userId'])
@Index('idx_user_contacts_type', ['tenantId', 'userId', 'type'])
@Index('idx_user_contacts_verified', ['tenantId', 'isVerified'])
export class UserContactORM {
  @PrimaryColumn('uuid')
  id: string;

  @Column({ name: 'tenant_id', type: 'uuid' })
  tenantId: string;

  @Column({ name: 'user_id', type: 'uuid' })
  userId: string;

  @Column({ type: 'varchar', length: 20 })
  type: string;

  @Column({ type: 'varchar', length: 255 })
  value: string;

  @Column({ name: 'display_name', type: 'varchar', length: 100, nullable: true })
  displayName: string | null;

  @Column({ name: 'is_verified', type: 'boolean', default: false })
  isVerified: boolean;

  @Column({ name: 'verified_at', type: 'timestamptz', nullable: true })
  verifiedAt: Date | null;

  // 通知设置
  @Column({ name: 'notification_enabled', type: 'boolean', default: false })
  notificationEnabled: boolean;

  @Column({ name: 'enabled_notification_types', type: 'text', array: true, default: '{}' })
  enabledNotificationTypes: string[];

  // 验证相关
  @Column({ name: 'verification_code', type: 'varchar', length: 10, nullable: true })
  verificationCode: string | null;

  @Column({ name: 'verification_expires_at', type: 'timestamptz', nullable: true })
  verificationExpiresAt: Date | null;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt: Date;
}
