package com.jwipc.sys.controller.pc;

import com.jwipc.log.annotation.AuditLogInter;
import com.jwipc.sys.dto.LoginParamDTO;
import com.jwipc.sys.dto.ResBtnDTO;
import com.jwipc.sys.logic.LoginLogic;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping(MODULE_ROOT + "/")
@Slf4j
@RequiredArgsConstructor
public class LoginRestContoller {
    private final LoginLogic loginLogic;

    @AuditLogInter(value = "用户登录", module = "系统")
    @PostMapping("login")
    public ResponseEntity login(HttpServletRequest request, LoginParamDTO loginParamDTO) {
        List<ResBtnDTO> result = loginLogic.login(request, loginParamDTO);
        return ResponseEntity.ok(result);
    }

    @PostMapping("noPasswordLogin")
    public ResponseEntity noPasswordLogin(Long userId) {
        List<ResBtnDTO> result = loginLogic.noPasswordLogin(userId);
        return ResponseEntity.ok(result);
    }
}
