package com.bonus.canteen.core.supply.api;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.menu.enums.RoleCodeV2Enum;
import com.bonus.canteen.core.supply.constant.MgrUserAuthPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MgrAuthApi {

   public boolean isSuperAdmin() {
//      MgrUserAuthPO authPO = this.getUserAuthPO();
//      String roleCode = authPO.getRoleCode();
//      return roleCode.startsWith(RoleCodeV2Enum.ROLE_ADMIN.key()) && roleCode.split("&&").length <= 1;
      return true;
   }

//   public MgrUserAuthPO getUserAuthPO() {
//      MgrUserAuthPO userAuthPO = new MgrUserAuthPO();
//      PigxUser user = SecurityUtils.getUser();
//      String roleCode = (String)SecureManager.getSubjectData().get("roleCode");
//      if (ObjectUtil.isEmpty(roleCode)) {
//         throw new LeException(I18n.getMessage("auth_user_no_role_code", new Object[0]));
//      } else {
//         Integer roleType;
//         if (roleCode.startsWith(RoleCodeV2Enum.ROLE_ADMIN.key())) {
//            if (CharSequenceUtil.split(roleCode, "&&").size() > 1) {
//               roleType = MgrRoleTypeV2Enum.ROLE_ADMIN.getKey();
//            } else {
//               roleType = LeConstants.DATA_DEFAULT_INTEGER;
//            }
//         } else if (roleCode.startsWith(RoleCodeV2Enum.ROLE_ORG.key())) {
//            roleType = MgrRoleTypeV2Enum.ROLE_ORG.getKey();
//         } else {
//            if (!roleCode.startsWith(RoleCodeV2Enum.ROLE_MERCHANT.key())) {
//               throw new LeException(I18n.getMessage("auth_role_type_error", new Object[0]));
//            }
//
//            roleType = MgrRoleTypeV2Enum.ROLE_MERCHANT.getKey();
//         }
//
//         userAuthPO.setUserId(user.getId());
//         userAuthPO.setRoleType(roleType);
//         userAuthPO.setRoleCode(roleCode);
//         userAuthPO.setUserName(user.getUsername());
//         return userAuthPO;
//      }
//   }

}
