package com.kcim.web;

import com.kcim.common.util.Result;
import com.kcim.dao.model.dto.LoginDTO;
import com.kcim.vo.CommonVO;
import com.kcim.vo.LoginVO;
import com.kcim.service.HospitalService;
import com.kcim.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "登录相关模块")
@RestController
@RequestMapping("")
public class LoginController {

    private final UserService userService;
    private final HospitalService hospitalService;

    public LoginController(UserService userService, HospitalService hospitalService) {
        this.userService = userService;
        this.hospitalService = hospitalService;
    }


    /**
     * 登录接口
     * @param loginDTO {@link LoginDTO} 登录相关参数
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("登录操作")
    public Result login(@RequestBody @Valid LoginDTO loginDTO) {
        LoginVO loginVO = userService.login(loginDTO);
        return Result.ok(loginVO);
    }

    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public Result logout() {
//        UserContext.getCurrentUser();
//        userService.logout(user);
        return Result.ok();
    }

    /**
     * 通过医院标识获取院区列表
     * @param sign 医院标识
     * @return
     */
    @ApiOperation("获取院区")
    @GetMapping("/getHospArea")
    public Result getHospArea(@RequestParam String sign) {
        List<CommonVO> commonVOs = hospitalService.getHospArea(sign);
        return Result.ok(commonVOs);
    }
}
