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

const FeaturedProperty = db.define("featuredproperties", {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true,
  },
  propertyId: {
    type: DataTypes.INTEGER,
    references: {
      model: "properties",
      key: "id",
    },
    allowNull: true,
  },
  userId: {
    type: DataTypes.INTEGER,
    references: {
      model: "users",
      key: "id",
    },
    allowNull: true,
  },
  planId: {
    type: DataTypes.INTEGER,
    references: {
      model: "plans",
      key: "id",
    },
    allowNull: true,
  },
  amount: {
    type: DataTypes.FLOAT,
    allowNull: false,
  },
  expiresIn: {
    type: DataTypes.DATE,
    allowNull: false,
  },
});

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

Plan.hasMany(FeaturedProperty, { foreignKey: "planId" });
FeaturedProperty.belongsTo(Plan, { foreignKey: "planId" });

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

module.exports = FeaturedProperty;
