package com.bonus.core.allocation.mobile.service;

import com.bonus.core.allocation.api.GlobalMetadataApi;
import com.bonus.core.common.enums.MetadataModelTypeEnum;
import com.bonus.core.allocation.mobile.model.EnterpriseCodeMetadataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@Component
public class EnterpriseCodeMetadataService {
   private static final Logger log = LoggerFactory.getLogger(EnterpriseCodeMetadataService.class);
   @Autowired
   @Lazy
   private GlobalMetadataApi globalMetadataApi;
//   @Autowired
//   @Lazy
//   private AliPayCompanyUtil aliPayCompanyUtil;
//   @Autowired
//   @Lazy
//   private AliPayPersonUtil aliPayPersonUtil;
//   @Autowired
//   @Lazy
//   private CustInfoApi custInfoApi;
//   @Autowired
//   @Lazy
//   private AesEncryptUtil aesEncryptUtil;
//   @Autowired
//   @Lazy
//   private EnterpriseCodeMetadataService enterpriseCodeMetadataService;
//   @Autowired
//   private AllocMetadataApi allocMetadataApi;
//   @Autowired
//   private CustCasualApi custCasualApi;

   public EnterpriseCodeMetadataModel queryMetadata() {
      return (EnterpriseCodeMetadataModel)this.globalMetadataApi.getModel(MetadataModelTypeEnum.ENTERPRISE_CODE, new EnterpriseCodeMetadataModel(), (Long)null, (Long)null);
   }

//   public void saveMetadata(EnterpriseCodeMetadataModel metadataModel) {
//      this.globalMetadataApi.saveModel(MetadataModelTypeEnum.ENTERPRISE_CODE, metadataModel, (Long)null, (Long)null);
//   }
//
//   public QYMInfoVO createEnterprise(QYMCreateDTO qymCreateDTO) {
//      String appId = this.allocMetadataApi.getMetadataValue(MetadataModelTypeEnum.MOBILE, LoginSourceTypeEnum.ALI_LIFE_CODE.value());
//      if (ObjectUtil.isNull(appId)) {
//         throw new LeException("企业入驻失败原因:未配置支付宝小程序appId");
//      } else {
//         QYMInfoVO qymInfoVO = this.aliPayCompanyUtil.createCompany(qymCreateDTO.getEnterpriseName(), this.queryMetadata().getEnterpriseAlias(), qymCreateDTO.getIdentity(), appId);
//         EnterpriseCodeMetadataModel enterpriseCodeMetadataModel = new EnterpriseCodeMetadataModel();
//         BeanUtil.copyProperties(qymCreateDTO, enterpriseCodeMetadataModel, new String[0]);
//         enterpriseCodeMetadataModel.setSignStatus(EnterpriseSignStatusEnum.UNACTIVATED.key());
//         enterpriseCodeMetadataModel.setEnterpriseId(qymInfoVO.getEnterpriseId());
//         enterpriseCodeMetadataModel.setIotGroupId(qymInfoVO.getIotGroupId());
//         enterpriseCodeMetadataModel.setIotLogicGroupId(qymInfoVO.getIotLogicGroupId());
//         enterpriseCodeMetadataModel.setSignUrl(qymInfoVO.getSignUrl());
//         this.saveMetadata(enterpriseCodeMetadataModel);
//         MerchantAliPayManagement merchantAliPayManagement = new MerchantAliPayManagement();
//         merchantAliPayManagement.setEntCodeEntId(qymInfoVO.getEnterpriseId());
//         return qymInfoVO;
//      }
//   }
//
//   public QYMUnsignVO unsignEnterprise(String enterpriseId) {
//      return this.aliPayCompanyUtil.unsignCompany(enterpriseId);
//   }
//
//   public String deleteEnterprise(QYMDeleteDTO qymCancelDTO) {
//      String enterpriseId = this.aliPayCompanyUtil.deleteCompany(qymCancelDTO.getEnterpriseId());
//      EnterpriseCodeMetadataModel enterpriseCodeMetadataModel = new EnterpriseCodeMetadataModel();
//      this.saveMetadata(enterpriseCodeMetadataModel);
//      Long merchantId = TenantContextHolder.getTenantId();
//      MerchantAliPayManagement merchantAliPayManagement = new MerchantAliPayManagement();
//      merchantAliPayManagement.setEntCodeEntId("");
//      return enterpriseId;
//   }
//
//   public QYMEnterpriseInfoDTO queryEnterprise(String enterpriseId) {
//      QYMEnterpriseInfoDTO enterpriseInfoDTO = this.aliPayCompanyUtil.queryCompany(enterpriseId);
//      EnterpriseCodeMetadataModel enterpriseCodeMetadataModel = this.enterpriseCodeMetadataService.queryMetadata();
//      if (ObjectUtil.isNotNull(enterpriseCodeMetadataModel)) {
//         log.info("查询企业码签约状态，并同步配置表：{}", enterpriseInfoDTO.toString());
//         if (ObjectUtil.isEmpty(enterpriseCodeMetadataModel.getAccountId()) && ObjectUtil.equals("ACTIVATED", enterpriseInfoDTO.getActivate())) {
//            enterpriseCodeMetadataModel.setAccountId(enterpriseInfoDTO.getAccountId());
//            enterpriseCodeMetadataModel.setSignStatus(enterpriseInfoDTO.getSignStatus());
//            enterpriseCodeMetadataModel.setActivate(enterpriseInfoDTO.getActivate());
//            enterpriseCodeMetadataModel.setEnterpriseCode(enterpriseInfoDTO.getEnterpriseCode());
//            this.enterpriseCodeMetadataService.saveMetadata(enterpriseCodeMetadataModel);
//         }
//      }
//
//      return enterpriseInfoDTO;
//   }
//
//   public QYMEmployeeInfoVO createEmployee(QYMCreateEmployeeDTO qymCreateEmployeeDTO) {
//      AlipayCommerceEcEmployeeAddResponse response = this.aliPayPersonUtil.addEmployee(qymCreateEmployeeDTO.getEnterpriseId(), qymCreateEmployeeDTO.getEmployeeName(), qymCreateEmployeeDTO.getUserId());
//      QYMEmployeeInfoVO qymEmployeeInfoVO = new QYMEmployeeInfoVO();
//      qymEmployeeInfoVO.setEmployeeId(response.getEmployeeId());
//      qymEmployeeInfoVO.setSinUrl(response.getSignUrl());
//      qymEmployeeInfoVO.setUniqueId(response.getIotUniqueId());
//      this.custCasualApi.updateEntCodeEmpId(qymCreateEmployeeDTO.getUserId(), response.getEmployeeId(), response.getIotUniqueId());
//      return qymEmployeeInfoVO;
//   }
//
//   public String modifyEmployeeInfo(String enterpriseId, String employeeId, String employeeName) {
//      AlipayCommerceEcEmployeeInfoModifyResponse response = this.aliPayPersonUtil.modifyEmployeeInfo(enterpriseId, employeeId, employeeName);
//      return response.getEmployeeId();
//   }
//
//   public EmployeeInfoDTO queryEmployeeInfo(String enterpriseId, String employeeId) {
//      return this.aliPayPersonUtil.queryEmployeeInfo(enterpriseId, employeeId);
//   }
//
//   public QYMEmployeeInviteVO queryEmployeeInvite(String enterpriseId) {
//      return this.aliPayPersonUtil.queryEmployeeInvite(enterpriseId);
//   }
//
//   public QYMEmployeeIdsVO queryEmployeeIds(String enterpriseId, String departmentId, Integer pageNum, Integer pageSize) {
//      return this.aliPayPersonUtil.queryEmployeeIds(enterpriseId, departmentId, pageNum, pageSize);
//   }
//
//   public void alipay(String authCode, String ordId) {
//      this.aliPayPersonUtil.alipay(authCode, ordId);
//   }
}
