import { DataTypes } from "sequelize";

export default (sequelize) => {
  const KycStage = sequelize.define("KycStage", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    code: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: true,
    },
    sequence: {
      type: DataTypes.INTEGER,
      allowNull: false,
      unique: true,
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
  }, {
    tableName: "KycStages",
    timestamps: true,
  });

  KycStage.associate = (models) => {
    KycStage.belongsToMany(models.SystemService, {
      through: models.KycStageService,
      foreignKey: "stageId",
      otherKey: "serviceId",
      as: "systemServices",
    });
  };

  return KycStage;
};
