use reqwest::Method;

use super::{urlencode, Client};
use crate::error::Error;
use crate::types::{CustomerFeaturesResponse, EntitlementsResponse, UsagePayload, UsageResponse};

impl Client {
    /// GET /api/me/entitlements - full customer entitlement + device snapshot.
    pub async fn entitlements(&self) -> Result<EntitlementsResponse, Error> {
        self.do_request::<_, EntitlementsResponse>(Method::GET, "/api/me/entitlements", None::<&()>)
            .await
    }

    pub async fn customer_features(
        &self,
        product: &str,
    ) -> Result<CustomerFeaturesResponse, Error> {
        let path = format!("/api/me/features/{}", urlencode(product));
        self.do_request::<_, CustomerFeaturesResponse>(Method::GET, &path, None::<&()>)
            .await
    }

    /// POST /api/me/usage - check or increment per-day usage counter.
    pub async fn track_usage(&self, payload: UsagePayload<'_>) -> Result<UsageResponse, Error> {
        self.do_request::<_, UsageResponse>(Method::POST, "/api/me/usage", Some(&payload))
            .await
    }

    /// POST /api/v1/usage/anonymous - anonymous usage tracking (HMAC only, no bearer).
    /// Use when the customer is not yet authenticated; the server applies the
    /// limits defined on the product's anonymous_plan.
    pub async fn track_anonymous_usage(
        &self,
        payload: UsagePayload<'_>,
    ) -> Result<UsageResponse, Error> {
        self.do_request::<_, UsageResponse>(Method::POST, "/api/v1/usage/anonymous", Some(&payload))
            .await
    }
}
