package com.its.api.its.controller;

import com.its.api.its.model.dto.LoginDto;
import com.its.api.its.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/auth")
@Api(tags = "00.공통-00.로그인/로그아웃")
public class LoginController {

    private final LoginService service;
/*
    @GetMapping(value = "/proxy/xxx", produces = {"application/json; charset=utf8"})
    public String proxy() {
        String url = "http://localhost/api/xxx";

        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(url, String.class);
    }
*/

    @ApiOperation(value = "로그인", response = LoginDto.class)
    @PostMapping(value = "/login", produces = {"application/json; charset=utf8"})
    public LoginDto login(@RequestBody @Valid final LoginDto.LoginReqDto req) {
        return this.service.login(req);
    }

    @ApiOperation(value = "로그아웃")
    @PostMapping(value = "/logout", produces = {"application/json; charset=utf8"})
    public void logout(@RequestBody @Valid final LoginDto.LogoutReqDto req) {
        this.service.logout(req);
    }

}
