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

const Feedback = db.define("feedbacks", {
  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,
  },
  rating: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
  },
  status: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
  },
});

User.hasOne(Feedback, { foreignKey: "userId" });
Feedback.belongsTo(User, { foreignKey: "userId" });

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

module.exports = Feedback;
