const { on } = require("nodemailer/lib/xoauth2");
const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  const ClientCollabDetail = sequelize.define(
    "clientcollabdetail",
    {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      creation: { type: DataTypes.DATE, allowNull: false },
      modified: { type: DataTypes.DATE, allowNull: false },
      modified_by: { type: DataTypes.INTEGER, allowNull: false },
      owner: { type: DataTypes.INTEGER, allowNull: false },
      enabled: { type: DataTypes.BOOLEAN, allowNull: false },

      persentase_ks: { type: DataTypes.DECIMAL(5, 2), allowNull: true },
      is_saved: { type: DataTypes.TINYINT, allowNull: true },
      is_submitted: { type: DataTypes.TINYINT, allowNull: true },

      item_id: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: { model: "items", key: "id" },
      },
      clientcollab_id: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: { model: "clientcollabs", key: "id" },
      },
      client_id: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: { model: "clients", key: "id" },
      },
      outlet_id: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: { model: "outlets", key: "id" },
      },
    },
    {
      tableName: "clientcollabdetails",
    },
    {
      freezeTableName: true,
    }
  );

  ClientCollabDetail.associate = function (models) {
    ClientCollabDetail.belongsTo(models.ClientCollab, {
      foreignKey: "clientcollab_id",
      as: "clientcollab",
      onDelete: "CASCADE",
    });
    ClientCollabDetail.belongsTo(models.Item, { foreignKey: "item_id", as: "item" });
    ClientCollabDetail.belongsTo(models.Client, { foreignKey: "client_id", as: "client" });
    ClientCollabDetail.belongsTo(models.Outlet, { foreignKey: "outlet_id", as: "outlet" });
  };

  return ClientCollabDetail;
};
