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

@Entity('user_subscriptions')
@Index('idx_user', ['user_id'])
@Index('idx_plan', ['plan_id'])
@Index('idx_status', ['status'])
@Index('idx_end', ['ends_at'])
export class UserSubscription {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

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

  @Column({ type: 'bigint', unsigned: true })
  plan_id: number;

  @Column({ type: 'datetime' })
  starts_at: Date;

  @Column({ type: 'datetime' })
  ends_at: Date;

  @Column({
    type: 'enum',
    enum: ['active', 'expired', 'cancelled'],
    default: 'active',
  })
  status: 'active' | 'expired' | 'cancelled';

  @CreateDateColumn()
  created_at: Date;
}
