use std::sync::Arc;

use crate::{
    network::query_builder::{QueryBuilder, QueryParam},
    tracking::trackable::{Trackable, TrackableBase, TrackingStateCell},
};

const EVENT_TYPE: &str = "activity";

pub(crate) struct ActivityEvent {
    trackable_base: TrackableBase,
}

impl ActivityEvent {
    pub fn new() -> Self {
        Self {
            trackable_base: TrackableBase::default(),
        }
    }
}

impl Trackable for ActivityEvent {
    fn encode_query(&self) -> String {
        QueryBuilder::with_params(vec![
            (QueryParam::Nonce, self.trackable_base.nonce().into()),
            (QueryParam::EventType, EVENT_TYPE.into()),
        ])
        .build()
    }

    fn state_cell(&self) -> &Arc<TrackingStateCell> {
        self.trackable_base.state_cell()
    }
}

#[cfg(test)]
mod tests {
    use crate::utils::test_utils::remove_nonce_parameter;

    use super::*;
    use rstest::rstest;

    #[rstest]
    fn test_event_type() {
        assert_eq!("activity", EVENT_TYPE);
    }

    #[rstest]
    fn test_encode_query() {
        // arrange
        let expected = format!("{}={}", QueryParam::EventType.as_str(), EVENT_TYPE);
        let ae = ActivityEvent::new();
        // act
        let actual = ae.encode_query();
        // assert
        let actual = remove_nonce_parameter(&actual);
        assert_eq!(expected, actual);
    }
}
