"""Playlist writer that makes demo saves explicit and network-free."""

import hashlib

import structlog

from app.domain.models import CreatedPlaylist


class DemoPlaylistWriter:
    """Simulate playlist writes with stable Spotify-shaped URLs."""

    async def create_playlist(self, name: str, description: str) -> CreatedPlaylist:
        """Return a deterministic fake playlist without an external write."""
        digest = hashlib.sha256(f"{name}\n{description}".encode()).hexdigest()[:12]
        playlist_id = f"demo-{digest}"
        return CreatedPlaylist(
            id=playlist_id,
            url=f"https://open.spotify.com/playlist/{playlist_id}",
        )

    async def add_tracks_to_playlist(self, playlist_id: str, track_uris: list[str]) -> None:
        """Log the simulated track addition without writing to Spotify."""
        structlog.get_logger().info(
            "demo_playlist_simulated",
            playlist_id=playlist_id,
            track_count=len(track_uris),
        )
