from spotify_shortcuts.run import run_shortcut
from spotify_shortcuts.shortcut import Shortcut
from spotify_shortcuts.config import load_config
from desktop_notifier import DesktopNotifierSync

SCOPES = [
    "user-library-read",
    "user-library-modify",
    "user-read-playback-state",
]


class SpotifyLike(Shortcut):
    def execute(self, client, config):
        if (playback := client.current_playback()) is None:
            print("No current playback found.")
            return

        if (uri := playback.get("item", {}).get("uri", None)) is None:
            print("No track URI found in current playback.")
            return

        client.current_user_saved_tracks_add(tracks=[uri])

        if config.notifications:
            dn = DesktopNotifierSync()
            dn.send(
                title="Track Liked",
                message=f"Track \"{playback.get('item', {}).get('name', '<no-name>')}\" by \"{
                ", ".join(a.get('name', '<no-name>') for a in playback.get('item', {}).get('artists', []))
                }\" has been liked.",
            )

    def get_help(self) -> str:
        return "Like the currently playing track."

    def get_scopes(self) -> list[str]:
        return SCOPES


def main():
    run_shortcut(SpotifyLike(), load_config())


if __name__ == "__main__":
    main()
