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

@Entity('plans')
@Index('idx_type', ['type'])
@Index('idx_active', ['is_active'])
export class Plan {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ length: 50, unique: true })
  code: string;

  @Column({ type: 'enum', enum: ['bundle', 'job_post', 'database'] })
  type: 'bundle' | 'job_post' | 'database';

  @Column({ length: 100 })
  name: string;

  @Column({ type: 'text', nullable: true })
  description: string;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  price: number;

  @Column({ type: 'decimal', precision: 10, scale: 2, nullable: true })
  original_price: number;

  @Column({ type: 'int', nullable: true })
  discount: number;

  @Column({ length: 10, default: 'INR' })
  currency: string;

  @Column({ type: 'int', default: 0 })
  job_credits: number;

  @Column({ type: 'int', default: 0 })
  database_credits: number;

  @Column({ type: 'int', default: 0 })
  ai_credits: number;

  @Column({ type: 'int' })
  validity_days: number;

  @Column({
    type: 'int',
    nullable: true,
    comment: 'How many days the job remains active',
  })
  job_active_days: number;

  @Column({ type: 'json', nullable: true })
  features: any;

  @Column({ type: 'json', nullable: true })
  limits: any;

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

  @Column({ default: false })
  recommended: boolean;

  @CreateDateColumn()
  created_at: Date;
}
