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

export type PlanType = 'saas' | 'on_premise' | 'hybrid';

@Entity({ name: 'subscription_plans', schema: 'billing' })
export class SubscriptionPlan {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  // Identificacion
  @Index({ unique: true })
  @Column({ type: 'varchar', length: 30 })
  code: string;

  @Column({ type: 'varchar', length: 100 })
  name: string;

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

  // Tipo
  @Column({ name: 'plan_type', type: 'varchar', length: 20, default: 'saas' })
  planType: PlanType;

  // Precios base
  @Column({ name: 'base_monthly_price', type: 'decimal', precision: 12, scale: 2, default: 0 })
  baseMonthlyPrice: number;

  @Column({ name: 'base_annual_price', type: 'decimal', precision: 12, scale: 2, nullable: true })
  baseAnnualPrice: number;

  @Column({ name: 'setup_fee', type: 'decimal', precision: 12, scale: 2, default: 0 })
  setupFee: number;

  // Limites base
  @Column({ name: 'max_users', type: 'integer', default: 5 })
  maxUsers: number;

  @Column({ name: 'max_branches', type: 'integer', default: 1 })
  maxBranches: number;

  @Column({ name: 'storage_gb', type: 'integer', default: 10 })
  storageGb: number;

  @Column({ name: 'api_calls_monthly', type: 'integer', default: 10000 })
  apiCallsMonthly: number;

  // Modulos incluidos
  @Column({ name: 'included_modules', type: 'text', array: true, default: [] })
  includedModules: string[];

  // Plataformas incluidas
  @Column({ name: 'included_platforms', type: 'text', array: true, default: ['web'] })
  includedPlatforms: string[];

  // Features
  @Column({ type: 'jsonb', default: {} })
  features: Record<string, boolean>;

  // Estado
  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive: boolean;

  @Column({ name: 'is_public', type: 'boolean', default: true })
  isPublic: boolean;

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

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

  @DeleteDateColumn({ name: 'deleted_at', type: 'timestamptz', nullable: true })
  deletedAt: Date;
}
