use crate::api::helpers::{fetch_strava_data, put_to_strava_api, strava_v3};
use crate::models::{athlete, clubs};
use log::info;
use reqwest::blocking::Response;
use std::collections::HashMap;
use std::error::Error;
pub fn get_athlete(
access_token: &str,
) -> Result<athlete::AthleteCollection, Box<dyn std::error::Error>> {
info!("Calling Strava Athlete API");
fetch_strava_data("athlete".to_string(), access_token)
}
pub fn get_athlete_stats(
access_token: &str,
athlete_id: &str,
) -> Result<athlete::AthleteStats, Box<dyn std::error::Error>> {
info!("Calling Athlete Stats API\n");
fetch_strava_data(format!("athletes/{}/stats", athlete_id), access_token)
}
pub fn get_athlete_clubs(
access_token: &str,
) -> Result<clubs::ClubCollection, Box<dyn std::error::Error>> {
info!("Calling Athlete Clubs API\n");
fetch_strava_data("athlete/clubs".to_string(), access_token)
}
pub fn update_athlete_weight(access_token: &str, weight: &str) -> Result<Response, Box<dyn Error>> {
let url = strava_v3("athlete".to_string());
let mut params = HashMap::new();
params.insert("weight", weight);
info!("Calling Athlete Update Weight API\n");
put_to_strava_api(url, access_token, params)
}