use crate::error::{Error, Result};
use crate::http::{BaseClient, RequestOptions};
use crate::models::{
DeliveryCost, DeliveryData, DeliveryDataRequest, DeliveryMatch, DeliveryMatchRequest,
WarehousePremium, WarehouseReceipt, WarehouseReceiptRequest,
};
const PATH_GET_DELIVERY_DATA: &str = "/dceapi/forward/publicweb/deliverystat/delivery";
const PATH_GET_DELIVERY_MATCH: &str = "/dceapi/forward/publicweb/deliverystat/deliveryMatch";
const PATH_GET_WAREHOUSE_RECEIPT: &str = "/dceapi/forward/publicweb/deliverystat/warehouseReceipt";
const PATH_GET_DELIVERY_COST: &str = "/dceapi/forward/publicweb/deliverypara/deliveryCosts";
const PATH_GET_WAREHOUSE_PREMIUM: &str = "/dceapi/forward/publicweb/deliverypara/floatingAgio";
#[derive(Debug, Clone)]
pub struct DeliveryService {
client: BaseClient,
}
impl DeliveryService {
pub fn new(client: BaseClient) -> Self {
DeliveryService { client }
}
pub async fn get_delivery_data(
&self,
req: &DeliveryDataRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<DeliveryData>> {
self.client.do_post(PATH_GET_DELIVERY_DATA, req, opts).await
}
pub async fn get_delivery_match(
&self,
req: &DeliveryMatchRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<DeliveryMatch>> {
self.client.do_post(PATH_GET_DELIVERY_MATCH, req, opts).await
}
pub async fn get_warehouse_receipt(
&self,
req: &WarehouseReceiptRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<WarehouseReceipt>> {
self.client.do_post(PATH_GET_WAREHOUSE_RECEIPT, req, opts).await
}
pub async fn get_delivery_cost(
&self,
variety: &str,
opts: Option<RequestOptions>,
) -> Result<DeliveryCost> {
if variety.is_empty() {
return Err(Error::validation("variety", "variety is required"));
}
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct Request<'a> {
variety_code: &'a str,
}
let req = Request { variety_code: variety };
self.client.do_post(PATH_GET_DELIVERY_COST, &req, opts).await
}
pub async fn get_warehouse_premium(
&self,
variety: &str,
opts: Option<RequestOptions>,
) -> Result<Vec<WarehousePremium>> {
if variety.is_empty() {
return Err(Error::validation("variety", "variety is required"));
}
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct Request<'a> {
variety_code: &'a str,
}
let req = Request { variety_code: variety };
self.client.do_post(PATH_GET_WAREHOUSE_PREMIUM, &req, opts).await
}
}