use crate::client::EuroMail;
use crate::errors::EuroMailError;
use crate::types::{
    CreateInboundRouteParams, InboundRoute, ListParams, PaginatedResponse,
    UpdateInboundRouteParams,
};

impl EuroMail {
    pub async fn create_inbound_route(
        &self,
        params: &CreateInboundRouteParams,
    ) -> Result<InboundRoute, EuroMailError> {
        self.post("/v1/inbound-routes", params).await
    }

    pub async fn list_inbound_routes(
        &self,
        params: ListParams,
    ) -> Result<PaginatedResponse<InboundRoute>, EuroMailError> {
        let mut query: Vec<(&str, String)> = Vec::new();
        if let Some(page) = params.page {
            query.push(("page", page.to_string()));
        }
        if let Some(per_page) = params.per_page {
            query.push(("per_page", per_page.to_string()));
        }
        self.get_with_query("/v1/inbound-routes", &query).await
    }

    pub async fn get_inbound_route(&self, id: &str) -> Result<InboundRoute, EuroMailError> {
        self.get(&format!("/v1/inbound-routes/{id}")).await
    }

    pub async fn update_inbound_route(
        &self,
        id: &str,
        params: &UpdateInboundRouteParams,
    ) -> Result<InboundRoute, EuroMailError> {
        self.put(&format!("/v1/inbound-routes/{id}"), params).await
    }

    pub async fn delete_inbound_route(&self, id: &str) -> Result<(), EuroMailError> {
        self.delete(&format!("/v1/inbound-routes/{id}")).await
    }
}
