/****************************************************************************
 *
 *   Copyright (c) 2024 PX4 Development Team. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name PX4 nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ****************************************************************************/

/**
 * @file offline_task_planner.hpp
 *
 * Task planner for offline missions
 */

#pragma once

#include "offline_task.hpp"

namespace offline_task_manager
{

/**
 * @brief Plan offline tasks using nearest neighbor algorithm
 *
 * @param input_tasks Input tasks array
 * @param input_count Number of input tasks
 * @param start_lat Starting latitude (current position)
 * @param start_lon Starting longitude (current position)
 * @param battery_percent Current battery percentage
 * @param low_batt_threshold Low battery threshold
 * @param planned_tasks Output array for planned tasks
 * @param max_planned_tasks Maximum number of planned tasks
 * @param total_distance_m Output total distance in meters
 * @return Number of planned tasks, -1 on error
 */
int plan_offline_tasks(
	const OfflineTask *input_tasks,
	int input_count,
	double start_lat,
	double start_lon,
	float battery_percent,
	float low_batt_threshold,
	OfflineTask *planned_tasks,
	int max_planned_tasks,
	float &total_distance_m
);

/**
 * @brief Calculate Haversine distance between two points
 *
 * @param lat1 Latitude of point 1 in degrees
 * @param lon1 Longitude of point 1 in degrees
 * @param lat2 Latitude of point 2 in degrees
 * @param lon2 Longitude of point 2 in degrees
 * @return Distance in meters
 */
float haversine_distance(double lat1, double lon1, double lat2, double lon2);

} // namespace offline_task_manager
