import { DataTypes } from "sequelize";

export default (sequelize) => {
  const ExchangeRate = sequelize.define("ExchangeRate", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    baseCurrency: {
      type: DataTypes.STRING(10),
      allowNull: false,
    },
    targetCurrency: {
      type: DataTypes.STRING(10),
      allowNull: false,
    },
    rate: {
      type: DataTypes.DECIMAL(15, 4),
      defaultValue: 0.0000, // Used if rateSource is 'manual'
    },
    rateSource: {
      type: DataTypes.STRING(20),
      defaultValue: "manual", // 'manual', 'wewire', 'nine_psb', etc.
    },
    margin: {
      type: DataTypes.DECIMAL(15, 4),
      allowNull: false,
    },
    marginOperation: {
      type: DataTypes.ENUM("add", "subtract"),
      allowNull: false,
    },
  }, {
    tableName: "ExchangeRates",
    timestamps: true,
  });

  return ExchangeRate;
};
