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

const PropertyImage = db.define("propertyImages", {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true,
  },
  propertyId: {
    type: DataTypes.INTEGER,
    references: {
      model: "properties",
      key: "id",
    },
    allowNull: true,
  },
  path: {
    type: DataTypes.TEXT,
    allowNull: false,
  },
});

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

module.exports = PropertyImage;
