package com.red.circle.other.app.inner.endpoint.user.user;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.inner.model.cmd.user.UpdateUserExpandDeviceListBlockCmd;
import com.red.circle.other.inner.model.cmd.user.UserCheckInLogQryCmd;
import com.red.circle.other.inner.model.dto.user.ActiveUserCountryCodeDTO;
import com.red.circle.other.inner.model.dto.user.UserCheckInLogDTO;
import com.red.circle.other.inner.model.dto.user.UserExpandDTO;
import com.red.circle.other.app.inner.service.user.user.UserExpandClientService;
import com.red.circle.other.inner.endpoint.user.user.api.UserExpandClientApi;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户扩展信息.
 *
 * @author pengliang on 2023/10/13
 */
@Validated
@RestController
@RequestMapping(value = UserExpandClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class UserExpandClientEndpoint implements UserExpandClientApi {

  private final UserExpandClientService userExpandClientService;

  @Override
  public ResultResponse<Boolean> checkPurchasing(Long userId) {
    return ResultResponse.success(userExpandClientService.checkPurchasing(userId));
  }

  @Override
  public ResultResponse<Void> updatePurchasingToTrue(Long userId) {
    userExpandClientService.updatePurchasingToTrue(userId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<ActiveUserCountryCodeDTO>> findLatestActiveUserCountryCode(
      LocalDateTime lastActiveTime) {
    return ResultResponse.success(
        userExpandClientService.findLatestActiveUserCountryCode(lastActiveTime));
  }

  @Override
  public ResultResponse<Map<Long, UserExpandDTO>> mapUserExpand(Set<Long> userIds) {
    return ResultResponse.success(userExpandClientService.mapUserExpand(userIds));
  }

  @Override
  public ResultResponse<PageResult<UserCheckInLogDTO>> getCheckInLog(UserCheckInLogQryCmd query) {
    return ResultResponse.success(userExpandClientService.getCheckInLog(query));
  }

  @Override
  public ResultResponse<UserExpandDTO> getByUserId(Long userId) {
    return ResultResponse.success(userExpandClientService.getById(userId));
  }

  @Override
  public ResultResponse<Void> updateDeviceListBlock(UpdateUserExpandDeviceListBlockCmd cmd) {
    userExpandClientService.updateDeviceListBlock(cmd);
    return ResultResponse.success();
  }
}
