module.exports = function(sequelize, DataTypes) {
  const packages = sequelize.define(
    "packages",
    {
      id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true },
      title: { type: DataTypes.TEXT },
      description: { type: DataTypes.TEXT },
      price: { type: DataTypes.TEXT },
      duration: { type: DataTypes.TEXT },
      cta: { type: DataTypes.TEXT },
      included_sessions: { type: DataTypes.INTEGER },
      is_active: { type: DataTypes.BOOLEAN, defaultValue: true },
      importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  packages.associate = (db) => {
    db.packages.hasMany(db.clients, { as: "clients", foreignKey: { name: "packageId" }, constraints: false });
    db.packages.hasMany(db.resources, { as: "resources", foreignKey: { name: "packageId" }, constraints: false });
    db.packages.belongsTo(db.users, { as: "createdBy", constraints: false });
    db.packages.belongsTo(db.users, { as: "updatedBy", constraints: false });
  };

  return packages;
};
