package com.red.circle.other.app.command.user.query;


import com.red.circle.other.app.dto.cmd.user.relation.cp.UserCpLightCmd;
import com.red.circle.other.app.service.user.relation.UserCpLightCacheService;
import com.red.circle.other.app.service.user.relation.UserCpRelationService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 查询点亮CP
 *
 * @author zongpubin on 2023/11/16
 */
@Component
@AllArgsConstructor
public class UserCpLightQueryExe {

  private final UserCpLightCacheService userCpLightCacheService;

  public Boolean execute(UserCpLightCmd cmd) {
    if (StringUtils.isBlank(cmd.getNearUserId()) || Objects.equals(cmd.getNearUserId(), "null")) {
      return Boolean.FALSE;
    }

    if (Objects.nonNull(cmd.getType()) && Objects.equals(cmd.getType(), "APPOINT")) {
      return userCpLightCacheService.getCpLightAppoint(cmd.getReqUserId(),
              Long.parseLong(cmd.getNearUserId()),
              cmd.getReqSysOrigin().getOrigin());
    } else {
      return userCpLightCacheService.getCpLight(cmd.getReqUserId(),
              Long.parseLong(cmd.getNearUserId()),
              cmd.getReqSysOrigin().getOrigin());
    }
  }

  public Map<String, Boolean> executeMap(UserCpLightCmd cmd) {
    Map<String, Boolean> result = new HashMap<>();
    if (StringUtils.isBlank(cmd.getNearUserId()) || Objects.equals(cmd.getNearUserId(), "null")) {
      result.put("APPOINT", Boolean.FALSE);
      result.put("SPECIAL", Boolean.FALSE);
      return result;
    }

    result.put("APPOINT", userCpLightCacheService.getCpLightAppoint(cmd.getReqUserId(),
            Long.parseLong(cmd.getNearUserId()),
            cmd.getReqSysOrigin().getOrigin()));
    result.put("SPECIAL", userCpLightCacheService.getCpLight(cmd.getReqUserId(),
            Long.parseLong(cmd.getNearUserId()),
            cmd.getReqSysOrigin().getOrigin()));
    return result;
  }
}
