package de.oaa.libredeck.web.controller;

// -------------------------------------------------------------------------
// AuthController – commented out until Deezer re-enables app registration.
// Re-enable this class and DeezerConfig + the OAuth methods in DeezerProvider
// once a Deezer app-id / app-secret is available.
// -------------------------------------------------------------------------

// import de.libredeck.web.model.OAuthToken;
// import de.libredeck.web.service.streaming.StreamingProvider;
// import de.libredeck.web.service.streaming.StreamingProviderRegistry;
// import jakarta.servlet.http.HttpServletResponse;
// import jakarta.servlet.http.HttpSession;
// import lombok.RequiredArgsConstructor;
// import org.springframework.stereotype.Controller;
// import org.springframework.web.bind.annotation.*;
// import java.io.IOException;
// import java.util.UUID;
//
// @Controller
// @RequestMapping("/auth")
// @RequiredArgsConstructor
// public class AuthController {
//
//     static final String SESSION_TOKEN    = "access_token";
//     static final String SESSION_PROVIDER = "provider_id";
//     static final String SESSION_STATE    = "oauth_state";
//
//     private final StreamingProviderRegistry registry;
//
//     @GetMapping("/{provider}/login")
//     public void login(@PathVariable String provider,
//                       @RequestParam(defaultValue = "web") String platform,
//                       HttpSession session, HttpServletResponse response) throws IOException {
//         StreamingProvider p = registry.get(provider);
//         String state = platform + ":" + UUID.randomUUID();
//         session.setAttribute(SESSION_STATE, state);
//         session.setAttribute(SESSION_PROVIDER, provider);
//         response.sendRedirect(p.buildAuthorizationUrl(state));
//     }
//
//     @GetMapping("/callback")
//     public String callback(@RequestParam String code,
//                            @RequestParam(required = false) String state,
//                            HttpSession session) throws IOException {
//         String savedState = (String) session.getAttribute(SESSION_STATE);
//         if (savedState == null || !savedState.equals(state)) return "redirect:/?error=state_mismatch";
//         String providerId = (String) session.getAttribute(SESSION_PROVIDER);
//         OAuthToken token  = registry.get(providerId).exchangeCode(code);
//         session.setAttribute(SESSION_TOKEN, token.accessToken());
//         session.removeAttribute(SESSION_STATE);
//         if (state.startsWith("android:"))
//             return "redirect:libredeck://auth/callback?access_token=" + token.accessToken();
//         return "redirect:/playlists";
//     }
//
//     @GetMapping("/logout")
//     public String logout(HttpSession session) {
//         session.invalidate();
//         return "redirect:/";
//     }
// }
