use domain::{
    errors::DomainError,
    events::DomainEvent,
    value_objects::{MovieId, UserId},
};

use crate::watchlist::commands::RemoveFromWatchlistCommand;
use crate::watchlist::deps::RemoveFromWatchlistDeps;

pub async fn execute(
    deps: &RemoveFromWatchlistDeps,
    cmd: RemoveFromWatchlistCommand,
) -> Result<(), DomainError> {
    let user_id = UserId::from_uuid(cmd.user_id);
    let movie_id = MovieId::from_uuid(cmd.movie_id);
    deps.watchlist.remove(&user_id, &movie_id).await?;

    let _ = deps
        .event_publisher
        .publish(&DomainEvent::WatchlistEntryRemoved { user_id, movie_id })
        .await;

    Ok(())
}

#[cfg(test)]
#[path = "tests/remove.rs"]
mod tests;
