use std::sync::Arc;

use crate::model::entity::user::UserSubscribe;
use crate::repository::Repositories;
use result::code_error::CodeError;
use result::error_code;

pub async fn get_user_subscribe(
    repos: &Arc<Repositories>,
    token: &str,
) -> Result<UserSubscribe, anyhow::Error> {
    repos
        .user
        .find_one_subscribe_by_token(token)
        .await
        .map_err(|e| {
            anyhow::Error::new(CodeError::new_err_code_msg(
                error_code::DATABASE_QUERY_ERROR,
                &e.to_string(),
            ))
        })
}
