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

@Entity('geo_proxy_ip')
export class GeoProxyIpEntity extends BaseEntity {
  @Column({ comment: '名称' })
  name: string;

  @Column({ comment: '所属 Provider：local / tianqi', length: 32 })
  provider: string;

  @Column({ comment: '模式：local / third_party', length: 16 })
  mode: string;

  @Column({ comment: '代理主机', nullable: true, length: 128 })
  host: string;

  @Column({ comment: '代理端口', nullable: true })
  port: number;

  @Column({ comment: '协议 http/socks5', length: 8, default: 'http' })
  protocol: string;

  @Column({ comment: '用户名（明文）', nullable: true, length: 256 })
  username: string;

  @Column({ comment: '密码（明文）', nullable: true, length: 512 })
  password: string;

  @Column({ comment: '区域', nullable: true, length: 64 })
  region: string;

  @Column({ comment: 'ISP', nullable: true, length: 32 })
  isp: string;

  @Column({ comment: '出口 IP（与代理 IP 不同时填，测试得出）', nullable: true, length: 64 })
  exitIp: string;

  @Column({ comment: '开通城市（精确城市名，如「上海」）', nullable: true, length: 64 })
  city: string;

  @Column({ comment: '所属套餐 ID（如 202605031635378987）', nullable: true, length: 64 })
  packageId: string;

  @Column({ comment: 'Provider 侧外部 ID', nullable: true, length: 128 })
  externalId: string;

  @Index({ unique: true, where: 'bind_account_id IS NOT NULL' })
  @Column({ comment: '绑定账号 ID（强 1:1）', nullable: true })
  bindAccountId: number;

  @Column({ comment: '状态 active/expired/error/unbound', length: 16, default: 'unbound' })
  status: string;

  @Column({ comment: '健康检查延迟 ms', nullable: true })
  latencyMs: number;

  @Column({ comment: '上次检查时间', type: 'datetime', nullable: true })
  lastCheckAt: Date;

  @Column({ comment: '过期时间', type: 'datetime', nullable: true })
  expiresAt: Date;

  @Column({ comment: '扩展字段', type: 'json', nullable: true })
  extra: any;
}
