#![warn(missing_docs)]
use super::protos::{Envelope, RegisterQueueRequest, UnRegisterQueueRequest, RegisterExchangeRequest, 
    WatchRequest, UnWatchRequest, QueueMessageRequest
};
impl RegisterQueueRequest {
    pub fn byqueuename(queuename: &str) -> Self {
        Self {
            queuename: queuename.to_string()
        }
    }
    pub fn to_envelope(&self) -> Envelope {
        let any_message = prost_types::Any {
            type_url: "type.googleapis.com/openiap.RegisterQueueRequest".to_string(),
            value: {
                let mut buf = Vec::new();
                prost::Message::encode(self, &mut buf).unwrap_or(());
                buf
            },
        };
        Envelope {
            command: "registerqueue".into(),
            data: Some(any_message.clone()),
            ..Default::default() 
        }
    }
}
impl RegisterExchangeRequest {
    pub fn byexchangename(exchangename: &str) -> Self {
        Self {
            exchangename: exchangename.to_string(),
            addqueue: true,
            ..Default::default()
        }
    }
    pub fn to_envelope(&self) -> Envelope {
        let any_message = prost_types::Any {
            type_url: "type.googleapis.com/openiap.RegisterExchangeRequest".to_string(),
            value: {
                let mut buf = Vec::new();
                prost::Message::encode(self, &mut buf).unwrap_or(());
                buf
            },
        };
        Envelope {
            command: "registerexchange".into(),
            data: Some(any_message.clone()),
            ..Default::default() 
        }
    }
}
impl  UnRegisterQueueRequest {
    pub fn byqueuename(queuename: &str) -> Self {
        Self {
            queuename: queuename.to_string()
        }
    }
    pub fn to_envelope(&self) -> Envelope {
        let any_message = prost_types::Any {
            type_url: "type.googleapis.com/openiap.UnRegisterQueueRequest".to_string(),
            value: {
                let mut buf = Vec::new();
                prost::Message::encode(self, &mut buf).unwrap_or(());
                buf
            },
        };
        Envelope {
            command: "unregisterqueue".into(),
            data: Some(any_message.clone()),
            ..Default::default() 
        }
    }
    
}
impl WatchRequest {
    pub fn new(collectionname: &str, paths: Vec<String>) -> Self {
        Self {
            collectionname: collectionname.to_string(),
            paths
        }
    }
    pub fn to_envelope(&self) -> Envelope {
        let any_message = prost_types::Any {
            type_url: "type.googleapis.com/openiap.WatchRequest".to_string(),
            value: {
                let mut buf = Vec::new();
                prost::Message::encode(self, &mut buf).unwrap_or(());
                buf
            },
        };
        Envelope {
            command: "watch".into(),
            data: Some(any_message.clone()),
            ..Default::default() 
        }
    }
}
impl UnWatchRequest {
    pub fn byid(id: &str) -> Self {
        Self {
            id: id.to_string()
        }
    }
    pub fn to_envelope(&self) -> Envelope {
        let any_message = prost_types::Any {
            type_url: "type.googleapis.com/openiap.UnWatchRequest".to_string(),
            value: {
                let mut buf = Vec::new();
                prost::Message::encode(self, &mut buf).unwrap_or(());
                buf
            },
        };
        Envelope {
            command: "unwatch".into(),
            data: Some(any_message.clone()),
            ..Default::default() 
        }
    }
}
impl  QueueMessageRequest {
    pub fn byqueuename(queuename: &str, data: &str, striptoken: bool) -> Self {
        Self {
            queuename: queuename.to_string(),
            data: data.to_string(),
            striptoken,
            ..Default::default()
        }
    }
    pub fn byexchangename(exchangename: &str, data: &str, striptoken: bool) -> Self {
        Self {
            exchangename: exchangename.to_string(),
            data: data.to_string(),
            striptoken,
            ..Default::default()
        }
    }
    pub fn to_envelope(&self) -> Envelope {
        let any_message = prost_types::Any {
            type_url: "type.googleapis.com/openiap.QueueMessageRequest".to_string(),
            value: {
                let mut buf = Vec::new();
                prost::Message::encode(self, &mut buf).unwrap_or(());
                buf
            },
        };
        Envelope {
            command: "queuemessage".into(),
            data: Some(any_message.clone()),
            ..Default::default() 
        }
    }    
}