package cn.ey.biz.module.system.api.codeblock;

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.codeblock.dto.*;
import cn.ey.biz.module.system.controller.admin.codeblock.vo.CodeBlockTreeValueVO;
import cn.ey.biz.module.system.controller.admin.codeblock.vo.CodeBlockUserGpnVO;
import cn.ey.biz.module.system.controller.admin.codeblock.vo.CodeBlockWideTableVO;
import cn.ey.biz.module.system.convert.codeblock.CodeBlockConvert;
import cn.ey.biz.module.system.convert.codeblock.CodeBlockLegalEntityConvert;
import cn.ey.biz.module.system.dal.dataobject.codeblock.CodeBlockDO;
import cn.ey.biz.module.system.service.codeblock.CodeBlockLegalEntityService;
import cn.ey.biz.module.system.service.codeblock.CodeBlockWideService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

import static cn.ey.biz.module.system.enums.ApiConstants.VERSION;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class CodeBlockApiImpl implements CodeBlockApi {

    @Resource
    private CodeBlockWideService codeBlockWideService;

    @Resource
    private CodeBlockLegalEntityService legalEntityService;


    @Override
    public R<CodeBlockWideTableDTO> getCodeBlockList(CodeBlockWideTableReqDTO codeBlockWideTableReq) {
        CodeBlockWideTableVO codeBlockWideTableVO = codeBlockWideService.queryCountryRegion(codeBlockWideTableReq);
        return R.success(CodeBlockConvert.INSTANCE.voConvertDto(codeBlockWideTableVO));
    }

    @Override
    public R<CodeBlockWideTableDTO> filterList(CodeBlockWideTableReqDTO reqDTO) {
        CodeBlockWideTableDTO codeBlockWideTableDTO = legalEntityService.filterList(reqDTO);
        return R.success(codeBlockWideTableDTO);
    }

    @Override
    public R<List<CodeBlockUserGpnDTO>> getCodeblockGpn(String app) {
        List<CodeBlockUserGpnVO> CodeBlockUserGpnVOList = codeBlockWideService.getCodeblockGpn(app);
        return R.success(CodeBlockLegalEntityConvert.INSTANCE.convert(CodeBlockUserGpnVOList));
    }

    @Override
    public R<CodeBlockLegalRespDTO> getLegalEffective(CodeBlockReqDTO reqDTO) {
        CodeBlockLegalRespDTO codeBlockLegalRespDTO = legalEntityService.getLegalEffective(reqDTO);
        return R.success(codeBlockLegalRespDTO);
    }

    @Override
    public R<CodeBlockInfoRespDTO> getCodeBlockInfo(String codeBlock) {
        CodeBlockInfoRespDTO codeBlockInfo = legalEntityService.getCodeBlockInfo(codeBlock);
        return R.success(codeBlockInfo);
    }

    @Override
    public R<List<CodeBlockInfoRespDTO>> getCodeBlockInfos(Collection<String> codeBlocks) {
       return  R.success(CodeBlockConvert.INSTANCE.convertList(codeBlockWideService.getCodeBlockDetailList(codeBlocks)));
    }

    @Override
    public R<List<CodeBlockTreeValueDTO>> treeCodeList() {
        List<CodeBlockTreeValueVO> list = codeBlockWideService.treeCodeList();
        return R.success(CodeBlockLegalEntityConvert.INSTANCE.treeVoConvertDTOList(list));
    }

    @Override
    public R<List<CodeBlockTreeValueDTO>> treeCityCodeList() {
        List<CodeBlockTreeValueVO> list = codeBlockWideService.treeCityCodes();
        return R.success(CodeBlockLegalEntityConvert.INSTANCE.treeVoConvertDTOList(list));
    }

    @Override
    public R<List<CodeBlockGpnRespDTO>> getGpnCodeblock(String app, String gpn) {
        List<CodeBlockDO> codeBlockDOList=codeBlockWideService.getCodeBlockListByGpn(app,gpn,null);
        return R.success(CodeBlockLegalEntityConvert.INSTANCE.convertDTO(codeBlockDOList));
    }

    @Override
    public R<List<CodeBlockGpnRespDTO>> getGpnCodeblock(String app, String gpn,String configType) {
        List<CodeBlockDO> codeBlockDOList=codeBlockWideService.getCodeBlockListByGpn(app,gpn,configType);
        return R.success(CodeBlockLegalEntityConvert.INSTANCE.convertDTO(codeBlockDOList));
    }

    @Override
    public R<List<String>> getGpnListByCodeblock(String app, String codeBlock, String configType) {
        List<String> gpnList=codeBlockWideService.getGpnListByCodeblock(app,codeBlock,configType);
        return  R.success(gpnList);
    }

}
