import { DataTypes } from "sequelize";

export default (sequelize) => {
  const MerchantWebhookLog = sequelize.define("MerchantWebhookLog", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    merchantId: {
      type: DataTypes.UUID,
      allowNull: false,
    },
    customerId: {
      type: DataTypes.UUID,
      allowNull: true,
    },
    event: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    webhookUrl: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    payload: {
      type: DataTypes.JSON,
      allowNull: false,
    },
    status: {
      type: DataTypes.ENUM("pending", "delivered", "failed", "skipped"),
      defaultValue: "pending",
    },
    response: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
    attempts: {
      type: DataTypes.INTEGER,
      defaultValue: 1,
    }
  }, {
    timestamps: true,
  });

  return MerchantWebhookLog;
};
