const { DataTypes } = require("sequelize");
const { db } = require("../utils");
const Property = require("./Property");

const PropertyFeatures = db.define("propertyFeatures", {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true,
  },
  propertyId: {
    type: DataTypes.INTEGER,
    references: {
      model: "properties",
      key: "id",
    },
    allowNull: true,
  },
  key: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  value: {
    type: DataTypes.STRING,
    allowNull: false,
  },
});

Property.hasMany(PropertyFeatures, { foreignKey: "propertyId" });
PropertyFeatures.belongsTo(Property, { foreignKey: "propertyId" });

module.exports = PropertyFeatures;
