import spotipy
from spotipy.oauth2 import SpotifyPKCE

class Authorize:
    def __init__(self):
        self.scope = (
            "playlist-modify-public user-read-playback-state "
            "user-read-currently-playing user-read-recently-played user-follow-read"
        )
        self.auth_sp = None  # Use None instead of empty string for objects
        self.client_id = "b753d36cb3d4452b9f3c6d90541cfc6a"
        self.redirect_uri = "http://127.0.0.1:8888/callback"

    def auth(self):
        sp_oauth = SpotifyPKCE(
            client_id=self.client_id,
            redirect_uri=self.redirect_uri,
            scope=self.scope
        )
        self.auth_sp = spotipy.Spotify(auth_manager=sp_oauth)
        return self.auth_sp

# Example usage:
# if __name__ == "__main__":
#     auth = Authorize()
#     sp = auth.auth()
#     print(sp.current_user())

#try:
#    current_user = sp.current_user_playlists()
#    #current_user = sp.current_user()
#
#    print("Current user's profile:")
#    print(current_user)

#except Exception as e:
#    print("An error occurred:", e)

# By using `SpotifyPKCE`, you can take advantage of the Authorization
# Code with PKCE flow, which provides an additional layer of security for your application.