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

import com.red.circle.common.business.dto.cmd.UserIdCmd;
import com.red.circle.other.app.dto.clientobject.user.user.UserRegionCO;
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 用户区域查询.
 *
 * @author pengliang on 2023/6/10
 */
@Component
@RequiredArgsConstructor
public class UserRegionQryExe {

  private final UserRegionGateway userRegionGateway;

  public UserRegionCO execute(UserIdCmd cmd) {
    return Optional.ofNullable(userRegionGateway.getUserRegion(cmd.getUserId()))
        .map(region -> new UserRegionCO()
            .setRegionId(region.getRegionId())
            .setRegionCode(region.getRegionCode()))
        .orElse(null);
  }

}
