import { v4 as uuidv4 } from 'uuid';

export interface ExchangeRate {
  id: string;
  from_currency: string;
  to_currency: string;
  rate: number;
  inverse_rate: number;
  last_updated: Date;
  source: string;
  created_by: string;
  updated_by: string;
  created_at: Date;
  updated_at: Date;
}

export interface ExchangeRateHistory {
  id: string;
  from_currency: string;
  to_currency: string;
  rate: number;
  date: Date;
  source: string;
  created_by: string;
  created_at: Date;
}

export class ExchangeRateModel {
  static create(data: Omit<ExchangeRate, 'id' | 'created_at' | 'updated_at'>): ExchangeRate {
    const now = new Date();
    return {
      id: uuidv4(),
      ...data,
      created_at: now,
      updated_at: now,
    };
  }

  static update(rate: ExchangeRate, data: Partial<Omit<ExchangeRate, 'id' | 'created_at'>>): ExchangeRate {
    return {
      ...rate,
      ...data,
      updated_at: new Date(),
    };
  }

  static createHistory(data: Omit<ExchangeRateHistory, 'id' | 'created_at'>): ExchangeRateHistory {
    const now = new Date();
    return {
      id: uuidv4(),
      ...data,
      created_at: now,
    };
  }
}
