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

@Entity('unlocked_profiles')
@Unique('unique_unlock', ['recruiter_user_id', 'seeker_user_id', 'action_type']) // Updated unique constraint
export class UnlockedProfile {
  @PrimaryGeneratedColumn()
  id: number;

  @Index()
  @Column()
  recruiter_user_id: number; // Links to the recruiter (user_id) who unlocked it

  @Index()
  @Column()
  seeker_user_id: number; // Links to the candidate (user_id) being unlocked

  @Column({
    type: 'enum',
    enum: ['free_limit', 'database_credits', 'subscription_bundle'],
    default: 'database_credits',
  })
  unlock_type: string;

  @Column({ type: 'varchar', length: 50, nullable: true })
  action_type: string; // 'Profile View' or 'CV Download'

  @Column({ default: 0 })
  credits_used: number; // 0 for free_limit, 1 for database_credits usually

  @Column({ type: 'timestamp' })
  unlocked_at: Date;

  @Column({ type: 'timestamp', nullable: true })
  expires_at: Date | null; // NULL if permanent

  @Column({ default: true })
  is_active: boolean;

  @Column({ nullable: true })
  subscription_id: number; // Link to subscription if applicable

  @CreateDateColumn()
  created_at: Date;

  @UpdateDateColumn()
  updated_at: Date;
}
