///
///
///
///
///
///
///
///
///
///
///
///
use crate::{client::Client, error::Error, payload, proto::common::*};

impl Client {
    /// List deals (filled order history) filtered by time range.
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    /// Timestamps are Unix milliseconds.  `max_rows` caps the result set.
    pub async fn deal_list(
        &self,
        ctid_trader_account_id: i64,
        from_timestamp: i64,
        to_timestamp: i64,
        max_rows: Option<i32>,
    ) -> Result<ProtoOaDealListRes, Error> {
        let req = ProtoOaDealListReq {
            payload_type: Some(payload::OA_DEAL_LIST_REQ as i32),
            ctid_trader_account_id,
            from_timestamp: Some(from_timestamp),
            to_timestamp: Some(to_timestamp),
            max_rows,
        };
        self.command(payload::OA_DEAL_LIST_REQ, req, payload::OA_DEAL_LIST_RES)
            .await
    }

    /// List deals associated with a specific position.
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    pub async fn deal_list_by_position(
        &self,
        ctid_trader_account_id: i64,
        position_id: i64,
        from_timestamp: Option<i64>,
        to_timestamp: Option<i64>,
    ) -> Result<ProtoOaDealListByPositionIdRes, Error> {
        let req = ProtoOaDealListByPositionIdReq {
            payload_type: Some(payload::OA_DEAL_LIST_BY_POSITION_ID_REQ as i32),
            ctid_trader_account_id,
            position_id,
            from_timestamp,
            to_timestamp,
        };

        self.command(
            payload::OA_DEAL_LIST_BY_POSITION_ID_REQ,
            req,
            payload::OA_DEAL_LIST_BY_POSITION_ID_RES,
        )
        .await
    }

    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    pub async fn deal_offset_list(
        &self,
        ctid_trader_account_id: i64,
        deal_id: i64,
    ) -> Result<ProtoOaDealOffsetListRes, Error> {
        let req = ProtoOaDealOffsetListReq {
            deal_id,
            ctid_trader_account_id,
            payload_type: Some(payload::OA_DEAL_OFFSET_LIST_REQ as i32),
            ..Default::default()
        };

        self.command(
            payload::OA_DEAL_OFFSET_LIST_REQ,
            req,
            payload::OA_DEAL_OFFSET_LIST_RES,
        )
        .await
    }
}

#[cfg(test)]
mod tests {

    #[async_std::test]
    async fn test() {}
}
