package org.ta.pddserver.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.ta.pddserver.model.api.request.UserRequest;
import org.ta.pddserver.utils.HttpRequestHandlerTool;
import org.ta.pddserver.utils.JsonResponse;

@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {
    @PostMapping("/login")
    public JSONObject login(HttpServletRequest request, @RequestBody UserRequest loginRequest) {
//        Authentication authentication = authenticationManager.authenticate(
//                new UsernamePasswordAuthenticationToken(
//                        loginRequest.getAccount(),
//                        loginRequest.getPassword()
//                )
//        );
//        SecurityContextHolder.getContext().setAuthentication(authentication);
//        RoleUserDetails userDetails = (RoleUserDetails) authentication.getPrincipal();
//        userDetails.setLoginIp(HttpRequestHandlerTool.getClientIP(request));
//        String jwt = jwtUtils.generateToken(userDetails);
//        JSONObject response = new JSONObject();
//        response.put("token", jwt);
//        response.put("username", userDetails.getUsername());
//        response.put("role", userDetails.getRole());
//        response.put("authorities", userDetails.getAuthorities());
//        return JsonResponse.generateLocalCommonSuccessResponse(response, null);
        return JsonResponse.generateOpenCommonFailedResponse(-1, "系统已经停用");
    }

    @PostMapping("/logout")
    public JSONObject logout(@RequestBody UserRequest loginRequest) {
//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        String username = authentication.getName();
//        userDetailsService.removeUser(username);
//        return JsonResponse.generateLocalCommonSuccessResponse(true, null);
        return JsonResponse.generateOpenCommonFailedResponse(-1, "系统已经停用");

    }

    @PostMapping("/checkUser")
    public JSONObject checkUser(@RequestBody UserRequest loginRequest) {
//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        RoleUserDetails userDetails = (RoleUserDetails) authentication.getPrincipal();
//        return JsonResponse.generateLocalCommonSuccessResponse(userDetails, null);
        return JsonResponse.generateOpenCommonFailedResponse(-1, "系统已经停用");
    }
}
