export default (sequelize, DataTypes) => {
  const KybDocument = sequelize.define("KybDocument", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    applicationId: {
      type: DataTypes.UUID,
      allowNull: false,
      references: { model: "KybApplications", key: "id" },
    },
    documentType: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "e.g. Certificate of Incorporation, Utility Bill, Memorandum of Association",
    },
    documentUrl: {
      type: DataTypes.STRING,
      allowNull: false,
      validate: { isUrl: true },
    },
    status: {
      type: DataTypes.ENUM("Pending", "Approved", "Rejected", "ActionRequired"),
      defaultValue: "Pending",
    },
    rejectionReason: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
  }, {
    tableName: "KybDocuments",
    timestamps: true,
  });

  KybDocument.associate = (models) => {
    KybDocument.belongsTo(models.KybApplication, {
      foreignKey: "applicationId",
      as: "application",
    });
  };

  return KybDocument;
};
