const Sequelize = require("sequelize");
const sequelizeConnect = require("../connection/db");
const SellerGroupPermissions = require("./SellerGroupPermissions");
const SellerGroupMembers = require("./SellerGroupMembers");

const SellerGroups = sequelizeConnect.define(
  "seller_groups",
  {
    id: {
      type: Sequelize.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
    },
    name: {
      type: Sequelize.STRING(150),
      allowNull: false,
    },
    seller_company_id: {
      type: Sequelize.BIGINT,
      allowNull: false,
    },
    status: {
      type: Sequelize.BOOLEAN,
      allowNull: false,
      defaultValue: true,
    },
  },
  {
    tableName: "seller_groups",
    timestamps: false,
  }
);

SellerGroups.hasMany(SellerGroupPermissions, {
  foreignKey: "seller_group_id",
  as: "group_permissions"
})

SellerGroups.hasMany(SellerGroupMembers, {
  foreignKey: "seller_group_id",
  as: "group_members"
})

module.exports = SellerGroups;
