export default (sequelize, DataTypes) => {
  const KybHistory = sequelize.define("KybHistory", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    applicationId: {
      type: DataTypes.UUID,
      allowNull: false,
      references: { model: "KybApplications", key: "id" },
    },
    adminId: {
      type: DataTypes.UUID,
      allowNull: true,
      references: { model: "Admins", key: "id" },
      comment: "If action taken by an admin",
    },
    action: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "e.g. Status Changed, Document Requested, Application Submitted",
    },
    previousStatus: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    newStatus: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    comment: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
  }, {
    tableName: "KybHistories",
    timestamps: true,
  });

  KybHistory.associate = (models) => {
    KybHistory.belongsTo(models.KybApplication, {
      foreignKey: "applicationId",
      as: "application",
    });
    KybHistory.belongsTo(models.Admin, {
      foreignKey: "adminId",
      as: "admin",
    });
  };

  return KybHistory;
};
