import { DataTypes } from "sequelize";

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

  AdminIpWhitelist.associate = (models) => {
    AdminIpWhitelist.belongsTo(models.Admin, { foreignKey: "addedBy", as: "creator" });
  };

  return AdminIpWhitelist;
};
