import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';
import { SubscriptionPlan } from './subscription-plan.entity';

export type LimitType = 'monthly' | 'daily' | 'total' | 'per_user';

@Entity({ name: 'plan_limits', schema: 'billing' })
export class PlanLimit {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ name: 'plan_id', type: 'uuid' })
  planId!: string;

  @ManyToOne(() => SubscriptionPlan, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'plan_id' })
  plan!: SubscriptionPlan;

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

  @Column({ name: 'limit_name', type: 'varchar', length: 255 })
  limitName!: string;

  @Column({ name: 'limit_value', type: 'integer' })
  limitValue!: number;

  @Column({ name: 'limit_type', type: 'varchar', length: 50, default: 'monthly' })
  limitType!: LimitType;

  @Column({ name: 'allow_overage', type: 'boolean', default: false })
  allowOverage!: boolean;

  @Column({ name: 'overage_unit_price', type: 'decimal', precision: 10, scale: 4, default: 0 })
  overageUnitPrice!: number;

  @Column({ name: 'overage_currency', type: 'varchar', length: 3, default: 'MXN' })
  overageCurrency!: string;

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

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