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

const Bookmark = db.define("bookmarks", {
  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.hasOne(Bookmark, { foreignKey: "userId" });
Bookmark.belongsTo(User, { foreignKey: "userId" });

Property.hasOne(Bookmark, { foreignKey: "propertyId" });
Bookmark.belongsTo(Property, { foreignKey: "propertyId" });

module.exports = Bookmark;
