const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  const UpCountryItinerary = sequelize.define(
    "upcountryitinerarie",
    {
      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 },

      date: { type: DataTypes.DATEONLY, allowNull: true },
      time: { type: DataTypes.TIME, allowNull: true },
      activity: { type: DataTypes.TEXT, allowNull: true },
      place: { type: DataTypes.STRING, allowNull: true },

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

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

  return UpCountryItinerary;
};
