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

const Report = db.define("reports", {
  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,
  },
  reportType: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
  },
});

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

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

module.exports = Report;
