use crate::sdk::decision_list::http::requests::DecisionListEntryRequest;
use crate::sdk::decision_list::http::responses::delete::DeleteDecisionListEntryResponse;
use crate::{KondutoClient, KondutoResult};

impl KondutoClient {
    pub async fn delete_from_list(
        &self,
        request: DecisionListEntryRequest,
    ) -> KondutoResult<DeleteDecisionListEntryResponse> {
        let endpoint = request.delete_endpoint().to_string();
        self.delete(&endpoint).await
    }
}

#[cfg(test)]
mod tests {
    use crate::email::Email;
    use crate::kind::DecisionListKind;
    use crate::sdk::decision_list::http::requests::DecisionListEntryRequest;
    use crate::sdk::decision_list::http::responses::create::StatusResponse;
    use crate::supports::tests::{TestContext, assert_api_success};

    #[tokio::test]
    pub async fn test_update_item_in_list() -> Result<(), Box<dyn std::error::Error>> {
        let ctx = TestContext::new().await;
        let email = Email::try_from("test@mail.com").expect("Invalid email");
        let request =
            DecisionListEntryRequest::email(DecisionListKind::Blocklist, email.clone(), None);
        
        let response = assert_api_success(ctx.client.delete_from_list(request).await);
        assert_eq!(response.status, StatusResponse::Ok);
        assert!(!response.message.is_empty());
        Ok(())
    }
}
