import { DataTypes } from "sequelize";

export default (sequelize) => {
  const MerchantServicePricing = sequelize.define("MerchantServicePricing", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    merchantId: {
      type: DataTypes.UUID,
      allowNull: false,
    },
    serviceName: {
      type: DataTypes.STRING(50),
      allowNull: false,
    },
    currency: {
      type: DataTypes.STRING(10),
      allowNull: false,
    },
    providerPercentage: {
      type: DataTypes.DECIMAL(5, 4),
      defaultValue: 0.0000,
    },
    providerFixedFee: {
      type: DataTypes.DECIMAL(15, 2),
      defaultValue: 0.00,
    },
    providerMinCap: {
      type: DataTypes.DECIMAL(15, 2),
      defaultValue: 0.00,
    },
    providerMaxCap: {
      type: DataTypes.DECIMAL(15, 2),
      defaultValue: 999999999.99,
    },
    customerPercentage: {
      type: DataTypes.DECIMAL(5, 4),
      defaultValue: 0.0000,
    },
    customerFixedFee: {
      type: DataTypes.DECIMAL(15, 2),
      defaultValue: 0.00,
    },
    customerMinCap: {
      type: DataTypes.DECIMAL(15, 2),
      defaultValue: 0.00,
    },
    customerMaxCap: {
      type: DataTypes.DECIMAL(15, 2),
      defaultValue: 999999999.99,
    },
    isActive: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
    },
  }, {
    tableName: "MerchantServicePricings",
    timestamps: true,
    indexes: [
      {
        unique: true,
        fields: ["merchantId", "serviceName", "currency"],
      },
    ],
  });

  MerchantServicePricing.associate = (models) => {
    MerchantServicePricing.belongsTo(models.Merchant, {
      foreignKey: "merchantId",
      as: "merchant",
    });
  };

  return MerchantServicePricing;
};
