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

@Entity('geo_account')
export class GeoAccountEntity extends BaseEntity {
  @Column({ comment: '账号昵称（用户填写）' })
  name: string;

  @Index()
  @Column({ comment: '平台 xiaohongshu/douyin/weibo/zhihu/taobao/wechat', length: 32 })
  platform: string;

  @Column({ comment: '登录账号/手机号（登录后自动从浏览器抓取）', length: 128, nullable: true })
  loginAccount: string;

  @Index({ unique: true, where: 'session_name IS NOT NULL' })
  @Column({ comment: 'netabrowser-cli sessionName，唯一标识浏览器 profile', length: 128, nullable: true })
  sessionName: string;

  @Index()
  @Column({ comment: '关联 Agent ID（哪个 Agent 来执行账号管理）', nullable: true })
  agentId: number;

  @Column({ comment: '浏览器指纹 seed（fingerprint-chromium 用，同账号每次启动指纹一致；不同账号 seed 不同→看作不同物理设备）', nullable: true })
  fingerprintSeed: number;

  @Column({ comment: 'cookies（明文 JSON，本地后台工具）', type: 'text', nullable: true })
  cookies: string;

  @Column({ comment: 'Cookie 抓取时间', type: 'datetime', nullable: true })
  cookieCapturedAt: Date;

  @Column({ comment: 'Cookie 最早过期时间（关键登录 cookie 中最早失效的）', type: 'datetime', nullable: true })
  cookieExpiresAt: Date;

  @Column({ comment: '登录状态 never/logged_in/expired/banned/deleted', length: 16, default: 'never' })
  loginStatus: string;

  @Index({ unique: true, where: 'proxy_id IS NOT NULL' })
  @Column({ comment: '绑定 IP', nullable: true })
  proxyId: number;

  @Column({ comment: '上次活跃时间', type: 'datetime', nullable: true })
  lastActiveAt: Date;

  @Column({ comment: '平台特定字段', type: 'json', nullable: true })
  extra: any;
}
