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

@Entity({ name: 'billing_plans', schema: 'public' })
export class Plan {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ type: 'varchar', length: 50, unique: true })
  name!: string; // 'free' | 'pro' | 'enterprise'

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

  @Column({ name: 'monthly_price_usd_cents', type: 'int', default: 0 })
  monthlyPriceCentsUsd!: number; // e.g. 4999 = $49.99

  @Column({ name: 'monthly_price_cny', type: 'int', default: 0 })
  monthlyPriceFenCny!: number; // e.g. 34900 = ¥349.00

  @Column({ name: 'included_tokens_per_month', type: 'bigint', default: 100000 })
  includedTokens!: number; // tokens per month included in plan

  @Column({ name: 'overage_rate_cents_per_m_token', type: 'int', default: 0 })
  overageRateCentsPerMTokenUsd!: number; // price per 1M overage tokens in USD cents

  @Column({ name: 'overage_rate_fen_per_m_token_cny', type: 'int', default: 0 })
  overageRateFenPerMTokenCny!: number; // price per 1M overage tokens in CNY fen

  @Column({ name: 'max_servers', type: 'int', default: 5 })
  maxServers!: number; // -1 = unlimited

  @Column({ name: 'max_users', type: 'int', default: 3 })
  maxUsers!: number; // -1 = unlimited

  @Column({ name: 'max_standing_orders', type: 'int', default: 10 })
  maxStandingOrders!: number; // -1 = unlimited

  @Column({ name: 'hard_limit_percent', type: 'int', default: 100 })
  hardLimitPercent!: number; // 100 = block at 100%, 150 = block at 150%, 0 = no limit

  @Column({ name: 'trial_days', type: 'int', default: 0 })
  trialDays!: number;

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

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

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