
module.exports = function(sequelize, DataTypes) {
  const claim_requests = sequelize.define(
    'claim_requests',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },
      status: {
        type: DataTypes.ENUM('PENDING', 'APPROVED', 'REJECTED'),
        defaultValue: 'PENDING',
        allowNull: false,
      },
      rejectionReason: {
        type: DataTypes.TEXT,
        allowNull: true,
      },
      createdAt: { type: DataTypes.DATE },
      updatedAt: { type: DataTypes.DATE },
      deletedAt: { type: DataTypes.DATE },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  claim_requests.associate = (db) => {
    db.claim_requests.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });

    db.claim_requests.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.claim_requests.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.claim_requests.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };

  return claim_requests;
};
