#!/usr/bin/env python3
"""OAuth flow to get Slides API access."""

import os
import json
from google_auth_oauthlib.flow import InstalledAppFlow

SCOPES = [
    "https://www.googleapis.com/auth/gmail.readonly",
    "https://www.googleapis.com/auth/gmail.send", 
    "https://www.googleapis.com/auth/gmail.modify",
    "https://www.googleapis.com/auth/presentations",  # Slides full access
]

# Use existing client credentials
CLIENT_CONFIG = {
    "installed": {
        "client_id": "231861791021-ls9bop3a8s8pojqsc54lle4q8iu6i1sd.apps.googleusercontent.com",
        "client_secret": "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",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "redirect_uris": ["http://localhost"]
    }
}

def main():
    flow = InstalledAppFlow.from_client_config(CLIENT_CONFIG, SCOPES)
    creds = flow.run_local_server(port=8080)
    
    token_data = {
        "token": creds.token,
        "refresh_token": creds.refresh_token,
        "token_uri": creds.token_uri,
        "client_id": creds.client_id,
        "client_secret": creds.client_secret,
        "scopes": list(creds.scopes),
        "universe_domain": "googleapis.com",
        "account": "",
        "expiry": creds.expiry.isoformat() if creds.expiry else None
    }
    
    # Save to temp file
    output_path = os.path.expanduser("~/slides_token.json")
    with open(output_path, "w") as f:
        json.dump(token_data, f, indent=2)
    
    print(f"Token saved to {output_path}")
    print(json.dumps(token_data))

if __name__ == "__main__":
    main()
