// =============================================================================
//  pid_outer_task.h -- 10 Hz outer-loop task (Sprint 3 / Sprint 5)
// =============================================================================
//
//  Sprint 3: HEADING_HOLD -- holds a magnetic/true heading setpoint.
//  Sprint 5: TRUE_COURSE  -- holds a COG setpoint (compensates current/wind).
//            TRACK_KEEPING -- COG hold + XTE proportional correction.
//
//  In all modes the output is a rudder setpoint handed to the inner loop.
//  In any other mode (STANDBY, DODGE) the task ticks idle (allowed=false),
//  bleeding the integrator so the transition back to active is smooth.
// =============================================================================

#pragma once

#include "pid_outer.h"

namespace arautopilot::pid {

void pid_outer_task_init();
void pid_outer_task_start();

// ----- HEADING_HOLD setpoint -----
void  pid_outer_set_heading_setpoint_deg(float setpoint_deg);
float pid_outer_heading_setpoint_deg();

// ----- TRUE_COURSE / TRACK_KEEPING setpoint -----
void  pid_outer_set_cog_setpoint_deg(float setpoint_deg);
float pid_outer_cog_setpoint_deg();

// ----- XTE parameters (TRACK_KEEPING) -----
void  pid_outer_set_xte_gain(float gain);         ///< deg correction / metre
void  pid_outer_set_xte_max_correction(float deg); ///< hard clamp
float pid_outer_xte_gain();
float pid_outer_xte_max_correction();

// ----- Telemetry -----
float pid_outer_last_rudder_setpoint_deg();
float pid_outer_last_error_deg();
float pid_outer_last_xte_correction_deg();  ///< 0 in non-TK modes

// ----- SOG / gain scheduling -----
void  pid_outer_set_speed_kn(float speed_kn);
float pid_outer_speed_kn();

void  pid_outer_update_gains(float kp, float ki, float kd);
void  pid_outer_get_gains(float& kp, float& ki, float& kd);

}  // namespace arautopilot::pid
