import { BaseEntity, transformerJson } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';

/**
 * 通知平台用户映射
 * 兼容飞书、微信、企业微信等平台的用户标识映射。
 */
@Entity('notification_user')
@Index(['platform', 'bizUserId'], { unique: true })
@Index(['platform', 'externalUserId'], { unique: true })
@Index(['platform', 'openId'], { unique: true })
export class NotificationUserEntity extends BaseEntity {
  @Index()
  @Column({ comment: '通知平台', length: 50 })
  platform: string;

  @Column({ comment: '平台应用ID', length: 100, nullable: true })
  appId: string;

  @Column({ comment: '业务侧用户ID', length: 100, nullable: true })
  bizUserId: string;

  @Column({ comment: '平台用户ID，如飞书user_id', length: 128, nullable: true })
  externalUserId: string;

  @Column({ comment: '平台open_id', length: 128, nullable: true })
  openId: string;

  @Column({ comment: '平台union_id', length: 128, nullable: true })
  unionId: string;

  @Column({ comment: '平台user_key/别名', length: 128, nullable: true })
  userKey: string;

  @Column({ comment: '会话/群聊ID', length: 128, nullable: true })
  chatId: string;

  @Column({ comment: '姓名', length: 100, nullable: true })
  name: string;

  @Column({ comment: '手机号', length: 50, nullable: true })
  mobile: string;

  @Column({ comment: '邮箱', length: 100, nullable: true })
  email: string;

  @Column({ comment: '状态 0=禁用 1=启用', default: 1 })
  status: number;

  @Column({
    comment: '扩展信息',
    type: 'json',
    transformer: transformerJson,
    nullable: true,
  })
  metadata: Record<string, any>;
}
