import { DataTypes } from "sequelize";

export default (sequelize) => {
  const Otp = sequelize.define("Otp", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    userId: {
      type: DataTypes.UUID,
      allowNull: false,
    },
    userType: {
      type: DataTypes.ENUM("admin", "merchant"),
      allowNull: false,
    },
    otp: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "Hashed OTP code",
    },
    purpose: {
      type: DataTypes.ENUM("login", "payout", "password_reset"),
      allowNull: false,
    },
    expiresAt: {
      type: DataTypes.DATE,
      allowNull: false,
    },
    isUsed: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
    },
    attempts: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      comment: "Number of failed verification attempts",
    },
  }, {
    tableName: "Otps",
    timestamps: true,
  });

  return Otp;
};
