#ifndef _Structures_h_
#define _Structures_h_

#include <string>   
#include <array>    
#include <algorithm> 
#include <cctype>  

using namespace std;
const int HCM4A_NO_INPUT_INT = -999;
const double HCM4A_NO_INPUT_DOUBLE = -999.0;
const std::string HCM4A_NO_INPUT_STRING = "";
const double HCM4A_ERROR_VALUE_DOUBLE = -999.0;
const double HCM4A_ERROR_VALUE_INT = -999;


struct PointToPoint_Input_Parameters {
    double Tx_Longitude;
    double Rx_Longitude;
    double Tx_Latitude;
    double Rx_Latitude;
    double Tx_Power;
    double Tx_H_Ant;
    double Rx_H_Ant;
    double Tx_Serv_area;
    double Rx_Serv_area;
    double Tx_Freq;
    double Rx_Freq;
    double Tx_Azi;
    double Rx_Azi;
    double Tx_Elev;
    double Rx_Elev;
    double Tx_Ant_gain;
    double Rx_Ant_gain;
    double Depol_loss;
    double PointDistance;  
    double Perm_FS_input;
    double Max_CBR_D_input; 
    double Cor_fact_frequ_diff; 
    
    int Tx_Type_of_Ant;
    int Rx_Type_of_Ant;
    int Chan_occup;
    int C_Mode;
    int D_to_border;
    int MaxCalcDistanceKm;
    int useAnnex1; 
    int Rx_H_Site_Ant;
    int Tx_H_Site_Ant;
    
    char Tx_Ant_typ_H[8];   
    char Tx_Ant_typ_V[8];
    char Rx_Ant_typ_H[8];
    char Rx_Ant_typ_V[8];
    char Tx_Desig_of_emis[10]; 
    char Rx_Desig_of_emis[10];
    char Sea_temperature[1];  
    char Border_path[256];    
    char Topo_path[256];
    char Morpho_path[256];
    char Debug_file[256];
    char Land_from[4];      
    char Land_to[4];    
    
	void ReadCoordinate(const std::string& source, bool isRx) {
		double lon, lat;
		try {
			std::string tmp = source.substr(0, 3);
			lon = std::stod(tmp);
			tmp = source.substr(4, 2);
			lon += std::stod(tmp) / 60;
			tmp = source.substr(6, 2);
			lon += std::stod(tmp) / 3600;
			if (std::toupper(source[3]) == 'W') lon = lon * -1;
		} catch (...) {
			return;
		}
		try {
			std::string tmp;
			tmp = source.substr(8, 2);
			lat = std::stod(tmp);
			tmp = source.substr(11, 2);
			lat += std::stod(tmp) / 60;
			tmp = source.substr(13, 2);
			lat += std::stod(tmp) / 3600;
			if (std::toupper(source[10]) == 'S') lat = lat * -1;
		} catch (...) {
			return;
		}
		if (isRx){
			Rx_Latitude = lat; Rx_Longitude = lon;
		} else {
			Tx_Latitude = lat; Tx_Longitude = lon;
		}
	}
	
	double TryReadOrValue(const std::string& Source, double Value = HCM4A_ERROR_VALUE_DOUBLE){
		try{
			std::string cleaned = Source;
			cleaned.erase(std::remove(cleaned.begin(), cleaned.end(), ' '), cleaned.end());
			return std::stod(cleaned);
		}catch (...){
			return Value;
		}
	};
	
	int TryReadOrValueI(const std::string& Source, int Value = HCM4A_ERROR_VALUE_INT){
		try{
			std::string cleaned = Source;
			cleaned.erase(std::remove(cleaned.begin(), cleaned.end(), ' '), cleaned.end());
			return std::stoi(cleaned);
		}catch (...){
			return Value;
		}
	};
};

struct PointToPoint_Output_Parameters {
    double Distance;
    double Dir_Tx_Rx;
    double Dir_Rx_Tx;
    double Tx_TCA;
    double Rx_TCA;
    double Tx_TCA_corr;
    double Rx_TCA_corr;
    double V_angle_Tx_Rx;
    double V_angle_Rx_Tx;
    double H_diff_angle_Tx_Rx;
    double V_diff_angle_Tx_Rx;
    double Tx_ant_corr;
    double Tx_ant_type_corr;
    double Power_to_Rx;
    double Free_space_FS;
    double Calculated_FS;
    double Perm_FS;
    double Perm_FS_from_table;
    double Table_CBR_D;
    double ERP_ref_Tx;
    double Time_percentage;
    double Prot_margin;
    double Tx_Longitude_Calc;
    double Tx_Latitude_Calc;
    double Rx_Longitude_Calc;
    double Rx_Latitude_Calc;
    double Heff_Tx;
    double Heff_Rx;
    double Heff;
    double D_sea_calculated;
    double Dh;
    double Dh_corr;
    double Land_FS;
    double Land_FS_old;
    double Sea_FS;
    
    double Corr_delta_f;
    double Delta_frequency;
    double Rx_ant_corr;
    double H_diff_angle_Rx_Tx;
    double V_diff_angle_Rx_Tx;
	double Depol_loss_calc;
	double Rx_ant_type_corr;
	    
	int ProfilePoints;
    int AnnexInFreqRange; // LongBool → int (4 байта)
    int Info[20]; // TInfoFlags = array[0..19] of LongBool → 20 × 4 = 80 байт
    int Tx_H_Site_Ant;
    int Rx_H_Site_Ant;
    int HCM_error;
    char Version[256];    
};

	
#endif