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

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

  @Column({ name: 'tenant_id', type: 'uuid' })
  tenantId!: string;

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

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

  @Column({ name: 'period_start', type: 'timestamptz', nullable: true })
  periodStart?: Date;

  @Column({ name: 'period_end', type: 'timestamptz', nullable: true })
  periodEnd?: Date;

  @Column({ name: 'total_input_tokens', type: 'bigint', default: 0 })
  totalInputTokens!: number;

  @Column({ name: 'total_output_tokens', type: 'bigint', default: 0 })
  totalOutputTokens!: number;

  @Column({ name: 'total_tokens', type: 'bigint', default: 0 })
  totalTokens!: number;

  @Column({ name: 'total_cost_usd', type: 'numeric', precision: 12, scale: 6, default: 0 })
  totalCostUsd!: number;

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

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

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