import { DataTypes } from "sequelize";

export default (sequelize) => {
  const MerchantIpWhitelist = sequelize.define("MerchantIpWhitelist", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    merchantId: {
      type: DataTypes.UUID,
      allowNull: false,
    },
    ipAddress: {
      type: DataTypes.STRING(100),
      allowNull: false,
      validate: {
        notEmpty: true,
      }
    },
    status: {
      type: DataTypes.ENUM("active", "inactive"),
      defaultValue: "active",
    }
  }, {
    tableName: "MerchantIpWhitelists",
    timestamps: true,
  });

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

  return MerchantIpWhitelist;
};
