package cn.hanghui.outapi.platform.tenant.controller;

import cn.hanghui.outapi.platform.common.config.log.Log;
import cn.hanghui.outapi.platform.common.controller.BaseController;
import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
import cn.hanghui.outapi.platform.common.utils.EnumUtils;
import cn.hanghui.outapi.platform.tenant.entity.dto.EnumCommonVo;
import cn.hanghui.outapi.platform.tenant.entity.dto.account.AccountDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.account.AccountSearch;
import cn.hanghui.outapi.platform.tenant.entity.dto.account.AccountVo;
import cn.hanghui.outapi.platform.tenant.entity.enums.*;
import cn.hanghui.outapi.platform.tenant.entity.enums.fkj.*;
import cn.hanghui.outapi.platform.tenant.service.AccountService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
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 java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shisl
 * @package cn.hanghui.outapi.platform.tenant.controller
 * @class AccountController
 * @date 2024/7/1 下午4:28
 * @description
 */
@Slf4j
@Api(tags = "账号授权管理")
@RestController
@RequestMapping(value = "/api/v1/auth/account")
public class AccountController extends BaseController {

    @Autowired
    private AccountService accountService;

    @ApiOperation(value = "添加或编辑授权账号")
    @PostMapping("/add")
    @ApiOperationSupport(order = 1)
    @Log(tag = LogTagEnum.AUTH_ACCOUNT,title = "添加/编辑账号授权",businessTypeEnum = BusinessTypeEnum.INSERT_UPDATE)
    public RestResult<Boolean> add(@RequestBody AccountDto dto) {
        return accountService.add(dto);
    }

    @ApiOperation(value = "删除授权账号")
    @PostMapping("/del/{accountId}")
    @Log(tag = LogTagEnum.AUTH_ACCOUNT,title = "删除账号授权",businessTypeEnum = BusinessTypeEnum.DELETE)
    public RestResult<Boolean> del(@PathVariable(value = "accountId") @ApiParam(value = "accountId", required = true) Long accountId) {
        return accountService.del(accountId);
    }

    @ApiOperation(value = "授权账号列表（分页）")
    @PostMapping("/page")
    @ApiOperationSupport(order = 3)
    public RestResult<IPage<AccountVo>> page(@RequestBody AccountSearch dto) {
        return accountService.page(dto);
    }

    @ApiOperation(value = "授权账号列表")
    @PostMapping("/list")
    @ApiOperationSupport(order = 4)
    public RestResult<List<AccountVo>> list() {
        return accountService.list();
    }

    @ApiOperation(value = "获取登录账号信息")
    @PostMapping("/query")
    @ApiOperationSupport(order = 4)
    public RestResult<AccountVo> query() {
        return accountService.query(getAccount());
    }




    @ApiOperation(value = "查询授权模块枚举列表")
    @PostMapping("/module/type/list")
    @ApiOperationSupport(order = 5)
    public RestResult<List<Map<Integer, String>>> queryModuleTypeList() {
        return RestResult.ok(EnumUtils.enumToListMap(ModuleTypeEnum.class));
    }


    @ApiOperation(value = "哇达西配置枚举合并")
    @PostMapping("/enum/common/list")
    @ApiOperationSupport(order = 5)
    public RestResult<Map<String, EnumCommonVo>> enumCommonMap() {
        Map<String, EnumCommonVo> map = new HashMap<>();
        this.addMap(map,"queryModuleTypeList","查询授权模块枚举列表",ModuleTypeEnum.class);
        this.addMap(map,"querySystemConfigList","查询系统配置枚举列表",SystemConfigEnum.class);
        this.addMap(map,"queryUseConfigList","查询使用配置枚举列表",UseConfigEnum.class);
        this.addMap(map,"queryPushConfigList","查询推送配置枚举列表",PushConfigEnum.class);
        this.addMap(map,"queryHhfaceFaceConfigList","查询HHFace支付宝人脸采集配置枚举列表",HhFaceFaceConfigEnum.class);
        this.addMap(map,"queryHhfaceCollectConfigList","查询HHFace采集配置枚举列表",HhFaceCollectConfigEnum.class);
        this.addMap(map,"queryHhfaceFuncConfigList","查询HHFace功能配置枚举列表",HhFaceFuncConfigEnum.class);
        this.addMap(map,"queryHhfaceHardwareConfigList","查询HHFace硬件配置枚举列表",HhFaceHardwareConfigEnum.class);
        this.addMap(map,"queryHhfacePushConfigList","查询HHFace推送配置枚举列表",HhFacePushConfigEnum.class);
        this.addMap(map,"queryHhfaceResultConfigList","查询HHFace结果页配置枚举列表",HhFaceResultConfigEnum.class);
        this.addMap(map,"queryHhfaceSystemConfigList","查询HHFace系统配置枚举列表",HhFaceSystemConfigEnum.class);
        this.addMap(map,"queryHhFaceThirdConfigList","查询HHFace三方接口配置枚举列表",HhFaceThirdConfigEnum.class);
        this.addMap(map,"queryHhFaceUseConfigList","查询HHFace使用配置枚举列表",HhFaceUseConfigEnum.class);
        this.addMap(map,"fkjUseConfigList","访客机使用配置枚举列表",FkjUseConfigEnum.class);
        this.addMap(map,"fkjCollectConfigList","访客机采集配置枚举列表",FkjCollectConfigEnum.class);
        this.addMap(map,"fkjQueryAddressConfigList","访客机查询地址配置枚举列表",FkjQuseyAddressConfigEnum.class);
        this.addMap(map,"fkjPushConfigList","访客机推送配置枚举列表",FkjPushConfigEnum.class);
        this.addMap(map,"fkjFuncConfigList","访客机功能配置枚举列表",FkjFuncConfigEnum.class);
        this.addMap(map,"fkjTimeoutDurationConfigList","访客机超时时长配置枚举列表",FkjTimeoutDurationConfigEnum.class);
        this.addMap(map,"fkjVoiceConfigList","访客机语音配置枚举列表",FkjVoiceConfigEnum.class);
        this.addMap(map,"fkjSystemConfigList","访客机系统配置枚举列表",FkjSystemConfigEnum.class);

        return RestResult.ok(map);
    }

    private void addMap(Map<String, EnumCommonVo> map, String code, String desc, Class<?> enumClass) {
        EnumCommonVo enumCommonVo = new EnumCommonVo();
        enumCommonVo.setCode(code);
        enumCommonVo.setDesc(desc);
        enumCommonVo.setList(EnumUtils.enumToListMap(enumClass));

        map.put(code,enumCommonVo);
    }

    @ApiOperation(value = "查询系统配置枚举列表")
    @PostMapping("/system/config/list")
    @ApiOperationSupport(order = 6)
    public RestResult<List<Map<String, String>>> querySystemConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(SystemConfigEnum.class));
    }

    @ApiOperation(value = "查询使用配置枚举列表")
    @PostMapping("/use/config/list")
    @ApiOperationSupport(order = 7)
    public RestResult<List<Map<String, String>>> queryUseConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(UseConfigEnum.class));
    }


    @ApiOperation(value = "查询推送配置枚举列表")
    @PostMapping("/push/config/list")
    @ApiOperationSupport(order = 8)
    public RestResult<List<Map<String, String>>> queryPushConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(PushConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace支付宝人脸采集配置枚举列表")
    @PostMapping("/hhface/face/config/list")
    @ApiOperationSupport(order = 9)
    public RestResult<List<Map<String, String>>> queryHhfaceFaceConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFaceFaceConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace采集配置枚举列表")
    @PostMapping("/hhface/collect/config/list")
    @ApiOperationSupport(order = 10)
    public RestResult<List<Map<String, String>>> queryHhfaceCollectConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFaceCollectConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace功能配置枚举列表")
    @PostMapping("/hhface/func/config/list")
    @ApiOperationSupport(order = 11)
    public RestResult<List<Map<String, String>>> queryHhfaceFuncConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFaceFuncConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace硬件配置枚举列表")
    @PostMapping("/hhface/hardware/config/list")
    @ApiOperationSupport(order = 12)
    public RestResult<List<Map<String, String>>> queryHhfaceHardwareConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFaceHardwareConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace推送配置枚举列表")
    @PostMapping("/hhface/push/config/list")
    @ApiOperationSupport(order = 13)
    public RestResult<List<Map<String, String>>> queryHhfacePushConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFacePushConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace结果页配置枚举列表")
    @PostMapping("/hhface/result/config/list")
    @ApiOperationSupport(order = 14)
    public RestResult<List<Map<String, String>>> queryHhfaceResultConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFaceResultConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace系统配置枚举列表")
    @PostMapping("/hhface/system/config/list")
    @ApiOperationSupport(order = 15)
    public RestResult<List<Map<String, String>>> queryHhfaceSystemConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFaceSystemConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace三方接口配置枚举列表")
    @PostMapping("/hhface/third/config/list")
    @ApiOperationSupport(order = 16)
    public RestResult<List<Map<String, String>>> queryHhFaceThirdConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFaceThirdConfigEnum.class));
    }

    @ApiOperation(value = "查询HHFace使用配置枚举列表")
    @PostMapping("/hhface/use/config/list")
    @ApiOperationSupport(order = 17)
    public RestResult<List<Map<String, String>>> queryHhFaceUseConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(HhFaceUseConfigEnum.class));
    }
    /**
     * 访客机配置
     */
    @ApiOperation(value = "访客机使用配置枚举列表")
    @PostMapping("/fkj/use/config/list")
    @ApiOperationSupport(order = 18)
    public RestResult<List<Map<String, String>>> fkjUseConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(FkjUseConfigEnum.class));
    }
    @ApiOperation(value = "访客机采集配置枚举列表")
    @PostMapping("/fkj/collect/config/list")
    @ApiOperationSupport(order = 19)
    public RestResult<List<Map<String, String>>> fkjCollectConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(FkjCollectConfigEnum.class));
    }
    @ApiOperation(value = "访客机查询地址配置枚举列表")
    @PostMapping("/fkj/query/address/config/list")
    @ApiOperationSupport(order = 20)
    public RestResult<List<Map<String, String>>> fkjQueryAddressConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(FkjQuseyAddressConfigEnum.class));
    }
    @ApiOperation(value = "访客机推送配置枚举列表")
    @PostMapping("/fkj/push/config/list")
    @ApiOperationSupport(order = 21)
    public RestResult<List<Map<String, String>>> fkjPushConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(FkjPushConfigEnum.class));
    }
    @ApiOperation(value = "访客机功能配置枚举列表")
    @PostMapping("/fkj/func/config/list")
    @ApiOperationSupport(order = 22)
    public RestResult<List<Map<String, String>>> fkjFuncConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(FkjFuncConfigEnum.class));
    }
    @ApiOperation(value = "访客机超时时长配置枚举列表")
    @PostMapping("/fkj/timeout/duration/config/list")
    @ApiOperationSupport(order = 23)
    public RestResult<List<Map<String, String>>> fkjTimeoutDurationConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(FkjTimeoutDurationConfigEnum.class));
    }
    @ApiOperation(value = "访客机语音配置枚举列表")
    @PostMapping("/fkj/voice/config/list")
    @ApiOperationSupport(order = 24)
    public RestResult<List<Map<String, String>>> fkjVoiceConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(FkjVoiceConfigEnum.class));
    }
    @ApiOperation(value = "访客机系统配置枚举列表")
    @PostMapping("/fkj/system/config/list")
    @ApiOperationSupport(order = 25)
    public RestResult<List<Map<String, String>>> fkjSystemConfigList() {
        return RestResult.ok(EnumUtils.enumToListMap(FkjSystemConfigEnum.class));
    }

}
