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

@Entity('invoices')
@Unique('uq_invoice_number', ['invoice_number'])
@Index('idx_user', ['user_id'])
@Index('idx_payment', ['payment_id'])
export class Invoice {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

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

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

  @Column({ length: 50 })
  invoice_number: string;

  @Column({ length: 20 })
  seller_gstin: string;

  @Column({ length: 20, nullable: true })
  buyer_gstin: string;

  @Column({ type: 'decimal', precision: 5, scale: 2, default: 0.0 })
  gst_rate: number;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  base_amount: number;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  gst_amount: number;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  total_amount: number;

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

  @CreateDateColumn()
  created_at: Date;
}
