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

const PropertyLead = db.define("propertyLeads", {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true,
  },
  userId: {
    type: DataTypes.INTEGER,
    references: {
      model: "users",
      key: "id",
    },
    allowNull: true,
  },
  propertyId: {
    type: DataTypes.INTEGER,
    references: {
      model: "properties",
      key: "id",
    },
    allowNull: true,
  },
});

User.hasMany(PropertyLead, { foreignKey: "userId" });
PropertyLead.belongsTo(User, { foreignKey: "userId" });

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

module.exports = PropertyLead;
