import { Entity, Column, Unique, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { CurrencyEntity } from './currency.entity';

/**
 * ExchangeRate entity — tenant-scoped.
 *
 * Stores manual exchange rates between currencies.
 * Only one active rate per from→to pair per tenant.
 */
@Entity('exchange_rates')
@Unique(['tenant_id', 'from_currency_id', 'to_currency_id'])
export class ExchangeRateEntity extends BaseEntity {
  @ManyToOne(() => CurrencyEntity)
  @JoinColumn({ name: 'from_currency_id' })
  from_currency: CurrencyEntity;

  @Column({ type: 'uuid' })
  from_currency_id: string;

  @ManyToOne(() => CurrencyEntity)
  @JoinColumn({ name: 'to_currency_id' })
  to_currency: CurrencyEntity;

  @Column({ type: 'uuid' })
  to_currency_id: string;

  @Column({ type: 'decimal', precision: 12, scale: 6 })
  rate: number;

  @Column({ type: 'date' })
  effective_date: string;

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