// Path: src/main/java/com/github/segator/proxylive/entity/LoginResult.java
// @Data
// @RequiredArgsConstructor
// public class LoginResult {
//     @NonNull
//     private String username;
//     @NonNull
//     private String jwt;
// }
// 
// Path: src/main/java/com/github/segator/proxylive/helper/JwtHelper.java
// @Component
// public class JwtHelper {
//     private JwtConfiguration jwtConfiguration;
// 
//     public JwtHelper(JwtConfiguration jwtConfiguration) {
//         this.jwtConfiguration = jwtConfiguration;
//     }
//     public String createJwtForClaims(String subject, List<GrantedAuthority> grantedAuthorities) {
//         Calendar calendar = Calendar.getInstance();
//         calendar.setTimeInMillis(Instant.now().toEpochMilli());
//         calendar.add(Calendar.HOUR, jwtConfiguration.getExpireInHours());
//         return createJwtForClaims(subject,grantedAuthorities,calendar.getTime());
//     }
//     public String createJwtForClaims(String subject, List<GrantedAuthority> grantedAuthorities,Date expirationDate) {
//         JwtBuilder builder =  Jwts.builder().setId("proxylive")
//             .setSubject(subject)
//             .claim("authorities",grantedAuthorities.stream()
//                     .map(GrantedAuthority::getAuthority)
//                     .collect(Collectors.toList()))
//             .setIssuedAt(new Date(System.currentTimeMillis()));
// 
//         if(expirationDate!=null) {
//             builder.setExpiration(expirationDate);
//         }
//         return builder.signWith(SignatureAlgorithm.HS512,
//                 jwtConfiguration.getSecret().getBytes()).compact();
//     }
// }
// 
// Path: src/main/java/com/github/segator/proxylive/service/AuthenticationService.java
// public interface AuthenticationService {
//    public boolean loginUser(String user, String password) throws Exception;
//    public List<GrantedAuthority> getUserRoles(String user);
// }


import com.github.segator.proxylive.entity.LoginResult;
import com.github.segator.proxylive.helper.JwtHelper;
import com.github.segator.proxylive.service.AuthenticationService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
package com.github.segator.proxylive.controller;


@RestController
public class AuthController {

    private final JwtHelper jwtHelper;
    private final AuthenticationService authenticationService;

    public AuthController(JwtHelper jwtHelper, AuthenticationService authenticationService) {
        this.jwtHelper = jwtHelper;
        this.authenticationService = authenticationService;
    }

    @PostMapping(path = "/login", consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE })
// Path: src/main/java/com/github/segator/proxylive/entity/LoginResult.java
// @Data
// @RequiredArgsConstructor
// public class LoginResult {
//     @NonNull
//     private String username;
//     @NonNull
//     private String jwt;
// }
// 
// Path: src/main/java/com/github/segator/proxylive/helper/JwtHelper.java
// @Component
// public class JwtHelper {
//     private JwtConfiguration jwtConfiguration;
// 
//     public JwtHelper(JwtConfiguration jwtConfiguration) {
//         this.jwtConfiguration = jwtConfiguration;
//     }
//     public String createJwtForClaims(String subject, List<GrantedAuthority> grantedAuthorities) {
//         Calendar calendar = Calendar.getInstance();
//         calendar.setTimeInMillis(Instant.now().toEpochMilli());
//         calendar.add(Calendar.HOUR, jwtConfiguration.getExpireInHours());
//         return createJwtForClaims(subject,grantedAuthorities,calendar.getTime());
//     }
//     public String createJwtForClaims(String subject, List<GrantedAuthority> grantedAuthorities,Date expirationDate) {
//         JwtBuilder builder =  Jwts.builder().setId("proxylive")
//             .setSubject(subject)
//             .claim("authorities",grantedAuthorities.stream()
//                     .map(GrantedAuthority::getAuthority)
//                     .collect(Collectors.toList()))
//             .setIssuedAt(new Date(System.currentTimeMillis()));
// 
//         if(expirationDate!=null) {
//             builder.setExpiration(expirationDate);
//         }
//         return builder.signWith(SignatureAlgorithm.HS512,
//                 jwtConfiguration.getSecret().getBytes()).compact();
//     }
// }
// 
// Path: src/main/java/com/github/segator/proxylive/service/AuthenticationService.java
// public interface AuthenticationService {
//    public boolean loginUser(String user, String password) throws Exception;
//    public List<GrantedAuthority> getUserRoles(String user);
// }


// Path: src/main/java/com/github/segator/proxylive/controller/AuthController.java
import com.github.segator.proxylive.entity.LoginResult;
import com.github.segator.proxylive.helper.JwtHelper;
import com.github.segator.proxylive.service.AuthenticationService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

package com.github.segator.proxylive.controller;


@RestController
public class AuthController {

    private final JwtHelper jwtHelper;
    private final AuthenticationService authenticationService;

    public AuthController(JwtHelper jwtHelper, AuthenticationService authenticationService) {
        this.jwtHelper = jwtHelper;
        this.authenticationService = authenticationService;
    }

    @PostMapping(path = "/login", consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE })
    public LoginResult login(