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

@Entity('user_profiles')
@Index('idx_user_profiles_tenant', ['tenantId'])
@Index('idx_user_profiles_user', ['userId'])
@Index('idx_user_profiles_nationality', ['tenantId', 'nationality'])
@Index('idx_user_profiles_target_countries', ['tenantId'], { where: "target_countries != '{}'" })
export class UserProfileORM {
  @PrimaryColumn('uuid')
  id: string;

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

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

  // 基本信息
  @Column({ name: 'full_name', type: 'varchar', length: 100, nullable: true })
  fullName: string | null;

  @Column({ name: 'birth_date', type: 'date', nullable: true })
  birthDate: Date | null;

  @Column({ type: 'varchar', length: 2, nullable: true })
  nationality: string | null;

  @Column({ name: 'current_country', type: 'varchar', length: 2, nullable: true })
  currentCountry: string | null;

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

  @Column({ name: 'marital_status', type: 'varchar', length: 20, nullable: true })
  maritalStatus: string | null;

  // 移民意向
  @Column({ name: 'target_countries', type: 'text', array: true, default: '{}' })
  targetCountries: string[];

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

  @Column({ name: 'planned_timeline', type: 'varchar', length: 20, nullable: true })
  plannedTimeline: string | null;

  @Column({ name: 'primary_purpose', type: 'text', nullable: true })
  primaryPurpose: string | null;

  // 教育背景
  @Column({ name: 'highest_education', type: 'varchar', length: 20, nullable: true })
  highestEducation: string | null;

  @Column({ name: 'education_records', type: 'jsonb', default: '[]' })
  educationRecords: Record<string, unknown>[];

  // 工作经历
  @Column({ name: 'current_occupation', type: 'varchar', length: 100, nullable: true })
  currentOccupation: string | null;

  @Column({ name: 'total_work_years', type: 'int', nullable: true })
  totalWorkYears: number | null;

  @Column({ name: 'work_records', type: 'jsonb', default: '[]' })
  workRecords: Record<string, unknown>[];

  // 语言能力
  @Column({ name: 'language_scores', type: 'jsonb', default: '[]' })
  languageScores: Record<string, unknown>[];

  // 家庭信息
  @Column({ name: 'family_members', type: 'jsonb', default: '[]' })
  familyMembers: Record<string, unknown>[];

  // 资产信息
  @Column({ name: 'net_worth_range', type: 'varchar', length: 20, nullable: true })
  netWorthRange: string | null;

  @Column({ name: 'has_business_experience', type: 'boolean', default: false })
  hasBusinessExperience: boolean;

  @Column({ name: 'business_years', type: 'int', nullable: true })
  businessYears: number | null;

  // 其他
  @Column({ name: 'has_overseas_experience', type: 'boolean', default: false })
  hasOverseasExperience: boolean;

  @Column({ name: 'has_criminal_record', type: 'boolean', nullable: true })
  hasCriminalRecord: boolean | null;

  @Column({ name: 'has_health_issues', type: 'boolean', nullable: true })
  hasHealthIssues: boolean | null;

  @Column({ name: 'additional_notes', type: 'text', nullable: true })
  additionalNotes: string | null;

  // 完成度
  @Column({ name: 'completion_percentage', type: 'int', default: 0 })
  completionPercentage: number;

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

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