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.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.user.pojo.param.PassWordRuleParam;
import com.njcn.user.pojo.po.UserStrategy;
import com.njcn.user.service.IPassWordRuleService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Description:
 * Date: 2024/7/11  18:01【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */

@RestController
@Slf4j
@Api(tags = "密码规则管理")
@RequestMapping("/password")
@AllArgsConstructor
public class PassWordRuleController extends BaseController {
    private final IPassWordRuleService passWordRuleService;


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("密码规则修改")
    @RequestMapping(value = "/ruleUpdate", method = RequestMethod.POST)
    public HttpResult<Boolean> ruleUpdate(@RequestBody @Validated PassWordRuleParam passWordRuleParam) {
        String methodDescribe = getMethodDescribe("ruleUpdate");
        Boolean flag = passWordRuleService.ruleUpdate(passWordRuleParam);

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

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取密码规则")
    @RequestMapping(value = "/getRule", method = RequestMethod.POST)
    public HttpResult<PassWordRuleParam> getRule() {
        String methodDescribe = getMethodDescribe("getRule");
        PassWordRuleParam passWordRuleParam = passWordRuleService.getRule();

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

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取用户策略")
    @RequestMapping(value = "/getUserStrategy", method = RequestMethod.POST)
    public HttpResult<UserStrategy> getUserStrategy() {
        String methodDescribe = getMethodDescribe("getUserStrategy");
        UserStrategy userStrategy = passWordRuleService.getUserStrategy();

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

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取用户策略列表")
    @RequestMapping(value = "/getUserStrategyList", method = RequestMethod.POST)
    public HttpResult<List<PassWordRuleParam>> getUserStrategyList() {
        String methodDescribe = getMethodDescribe("getUserStrategyList");
        List<PassWordRuleParam> userStrategys = passWordRuleService.getUserStrategyList();

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


    @OperateInfo(info = LogEnum.SYSTEM_SERIOUS)
    @ApiOperation("解锁超级管理员")
    @RequestMapping(value = "/unlockRoot", method = RequestMethod.POST)
    public HttpResult<Boolean> unlockRoot() {
        String methodDescribe = getMethodDescribe("unlockRoot");
        Boolean flag = passWordRuleService.unlockRoot();

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