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 = ""
        self.auth_access_code = ""
        
    def auth(self):
        sp_oauth = SpotifyPKCE(
            client_id="b753d36cb3d4452b9f3c6d90541cfc6a", 
            redirect_uri="http://127.0.0.1:8888/callback",
            scope=self.scope)

        self.auth_sp = spotipy.Spotify(auth_manager=sp_oauth)
        #self.auth_ref = sp_oauth.refresh_access_token(refresh_token="")
        #self.auth_access_code = sp_oauth.get_access_token()

        return self.auth_sp

#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.