module.exports = (sequelize, DataTypes) => {
  const HostManagers = sequelize.define(
    'HostManagers',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
        allowNull: false,
      },
      host_id: {
        type: DataTypes.UUID,
        allowNull: true,
        references: {
          model: 'users',
          key: 'id',
        },
      },
      email: {
        type: DataTypes.STRING,
        allowNull: true,
      },
      access: {
        type: DataTypes.ENUM('Full Access', 'Booking Manager', 'Read-Only'),
        allowNull: false,
      },
      status: {
        type: DataTypes.ENUM('Accepted', 'Declined', 'Pending', 'Inactive'),
        allowNull: false,
        defaultValue: 'Pending',
      },
    },
    {
      tableName: 'host_managers',
      timestamps: false,
    },
  );

  HostManagers.associate = (models) => {
    HostManagers.belongsTo(models.Users, {
      foreignKey: 'host_id',
      as: 'host',
    });

    HostManagers.belongsTo(models.Users, {
      foreignKey: 'email',
      targetKey: 'email_address',
      as: 'user',
    });
  };

  return HostManagers;
};
