package com.njcn.user.controller;


import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.user.enums.UserResponseEnum;
import com.njcn.user.pojo.param.AuthClientParam;
import com.njcn.user.pojo.param.PassWordRuleParam;
import com.njcn.user.pojo.po.AuthClient;
import com.njcn.user.service.IAuthClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.njcn.web.controller.BaseController;

import java.util.Objects;

/**
 *
 * @author hongawen
 * @since 2021-12-15
 */
@Slf4j
@Validated
@Api(tags = "客户端信息管理")
@AllArgsConstructor
@RestController
@RequestMapping("/authClient")
public class AuthClientController extends BaseController {

    private final IAuthClientService authClientService;


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getAuthClientByName/{clientName}")
    @ApiOperation("根据客户端名查询信息")
    @ApiImplicitParam(name = "clientName", value = "客户端名称", required = true)
    public HttpResult<AuthClient> getAuthClientByName(@PathVariable("clientName") String clientName) {
        String methodDescribe = getMethodDescribe("getAuthClientByName");
        LogUtil.njcnDebug(log, "{},客户端为：{}", methodDescribe, clientName);
        AuthClient authClient = authClientService.getAuthClientByName(clientName);
        if (Objects.isNull(authClient)) {
            throw new BusinessException(UserResponseEnum.NOT_FOUND_CLIENT);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, authClient, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("客户端会话配置更新")
    @RequestMapping(value = "/sessionConfigUpdate", method = RequestMethod.POST)
    public HttpResult<Boolean> sessionConfigUpdate(@RequestBody @Validated AuthClientParam authClientParam) {
        String methodDescribe = getMethodDescribe("sessionConfigUpdate");
        Boolean flag = authClientService.sessionConfigUpdate(authClientParam);

        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

}

