/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (c) 2022 Yves Revaz (yves.revaz@epfl.ch)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/
#ifndef SWIFT_SINK_STRUCT_DEFAULT_H
#define SWIFT_SINK_STRUCT_DEFAULT_H

/**
 * @brief Sink-related fields carried by each *gas* particle.
 */
struct sink_part_data {

  /*! ID of the sink that will swallow this #part. */
  long long swallow_id;

  /*! Gravitational potential of the particle */
  uint8_t can_form_sink;
};

/**
 * @brief Sink-related fields carried by each *sink* particle.
 */
struct sink_sink_data {

  /*! ID of the sink that will swallow this #sink. */
  long long swallow_id;

  /*! Mass of the sink that will swallow this #sink. */
  float swallow_mass;
};

/**
 * @brief Return the ID of the sink that should swallow this #part.
 *
 * @param s_data The #part's #sink_part_data structure.
 */
__attribute__((always_inline)) INLINE static long long sink_get_part_swallow_id(
    struct sink_part_data* s_data) {

  return s_data->swallow_id;
}

/**
 * @brief Update a given #part's sink data field to mark the particle has
 * not yet been swallowed.
 *
 * @param s_data The #part's #sink_part_data structure.
 */
__attribute__((always_inline)) INLINE static void
sink_mark_part_as_not_swallowed(struct sink_part_data* s_data) {

  s_data->swallow_id = -1;
}

/**
 * @brief Update a given #part's sink data field to mark the particle has
 * having been been swallowed.
 *
 * @param p_data The #part's #sink_part_data structure.
 */
__attribute__((always_inline)) INLINE static void sink_mark_part_as_swallowed(
    struct sink_part_data* s_data) {

  s_data->swallow_id = -2;
}

/**
 * @brief Update a given #sink's sink data field to mark the particle has
 * not yet been swallowed.
 *
 * @param s_data The #sink's #sink_sink_data structure.
 */
__attribute__((always_inline)) INLINE static void
sink_mark_sink_as_not_swallowed(struct sink_sink_data* s_data) {

  s_data->swallow_id = -1;
  s_data->swallow_mass = 0.f;
}

/**
 * @brief Update a given #sink's sink data field to mark the particle has
 * having been been swallowed.
 *
 * @param s_data The #sink's #bsink_sink_data structure.
 */
__attribute__((always_inline)) INLINE static void sink_mark_sink_as_merged(
    struct sink_sink_data* s_data) {

  s_data->swallow_id = -2;
  s_data->swallow_mass = -1.f;
}

/**
 * @brief Return the ID of the sink that should swallow this #sink.
 *
 * @param s_data The #sink's #sink_sink_data structure.
 */
__attribute__((always_inline)) INLINE static long long sink_get_sink_swallow_id(
    struct sink_sink_data* s_data) {

  return s_data->swallow_id;
}

#endif /* SWIFT_SINK_STRUCT_DEFAULT_H */
