import { DataTypes } from "sequelize";

export default (sequelize) => {
  const SystemService = sequelize.define("SystemService", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    code: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: true,
    },
    currency: {
      type: DataTypes.STRING(10),
      allowNull: true,
    },
    type: {
      type: DataTypes.ENUM("currency_based", "global_based"),
      allowNull: false,
      defaultValue: "global_based",
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
    isActive: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
      allowNull: false,
    },
    canReceive: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
      allowNull: false,
    },
    canSend: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
      allowNull: false,
    },
  }, {
    tableName: "SystemServices",
    timestamps: true,
  });

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

  return SystemService;
};
