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

const PropertyView = db.define("propertyViews", {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true,
  },
  propertyId: {
    type: DataTypes.INTEGER,
    references: {
      model: "properties",
      key: "id",
    },
    allowNull: true,
  },
  city: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  latitude: {
    type: DataTypes.STRING,
    allowNull: true
  },
  longitude: {
    type: DataTypes.STRING,
    allowNull: true
  }
});

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

module.exports = PropertyView;
