const { on } = require("nodemailer/lib/ses-transport");
const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  const UpCountryAccommodation = sequelize.define(
    "upcountryaccommodation",
    {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      creation: { type: DataTypes.DATE, allowNull: false },
      modified: { type: DataTypes.DATE, allowNull: false },
      modified_by: { type: DataTypes.INTEGER, allowNull: false },
      owner: { type: DataTypes.INTEGER, allowNull: false },
      enabled: { type: DataTypes.BOOLEAN, allowNull: false },

      who_requested: { type: DataTypes.STRING, allowNull: true },
      accommodation_type: { type: DataTypes.STRING, allowNull: true },
      from: { type: DataTypes.STRING, allowNull: true },
      to: { type: DataTypes.STRING, allowNull: true },
      from_date: { type: DataTypes.DATEONLY, allowNull: true },
      to_date: { type: DataTypes.DATEONLY, allowNull: true },
      purpose: { type: DataTypes.STRING, allowNull: true },
      files: { type: DataTypes.STRING, allowNull: true },

      // fk
      upcountry_id: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
          model: "upcountries",
          key: "id",
        },
      },
    },
    {
      tableName: "upcountryaccommodations",
      freezeTableName: true,
    }
  );

  UpCountryAccommodation.associate = (models) => {
    UpCountryAccommodation.belongsTo(models.UpCountry, {
      foreignKey: "upcountry_id",
      as: "upcountry",
      onDelete: "CASCADE",
    });
  };

  return UpCountryAccommodation;
};
