package com.red.circle.wallet.inner.endpoint.diamond;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.framework.web.spring.RequestCallable;
import com.red.circle.wallet.inner.endpoint.diamond.api.SalaryDiamondRunningWaterClientApi;
import com.red.circle.wallet.inner.model.cmd.UserSalaryDiamondCmd;
import com.red.circle.wallet.inner.model.cmd.UserSalaryDiamondRunningWaterQryCmd;
import com.red.circle.wallet.inner.model.dto.SalaryDiamondBalanceDTO;
import com.red.circle.wallet.inner.model.dto.UserSalaryDiamondRunningWaterDTO;
import com.red.circle.wallet.inner.service.diamond.SalaryDiamondRunningWaterClientService;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

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 zongpubin on 2024/3/14
 */
@Validated
@RestController
@RequestMapping(value = SalaryDiamondRunningWaterClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class SalaryDiamondRunningWaterClientEndpoint implements SalaryDiamondRunningWaterClientApi {

  private final SalaryDiamondRunningWaterClientService salaryDiamondRunningWaterClientService;

  @Override
  public ResultResponse<Void> add(UserSalaryDiamondRunningWaterDTO salaryDiamondRunningWater) {
    salaryDiamondRunningWaterClientService.add(salaryDiamondRunningWater);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> addBatch(
      List<UserSalaryDiamondRunningWaterDTO> salaryDiamondRunningWaters) {
    salaryDiamondRunningWaterClientService.addBatch(salaryDiamondRunningWaters);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<PageResult<UserSalaryDiamondRunningWaterDTO>> runningWaterPage(
      UserSalaryDiamondRunningWaterQryCmd query) {
    return ResultResponse.success(salaryDiamondRunningWaterClientService.runningWaterPage(query));
  }

  @Override
  public ResultResponse<Boolean> existsTrackId(String trackId) {
    return ResultResponse.success(salaryDiamondRunningWaterClientService.existsTrackId(trackId));
  }

  @Override
  public ResultResponse<Boolean> existsTrackId(Long userId, String event, String trackId) {
    return ResultResponse.success(salaryDiamondRunningWaterClientService.existsTrackId(userId, event, trackId));
  }

  @Override
  public CompletableFuture<ResultResponse<Void>> addAsync(UserSalaryDiamondRunningWaterDTO salaryDiamondRunningWater) {
    return RequestCallable.supplyAsync(() -> {
      salaryDiamondRunningWaterClientService.add(salaryDiamondRunningWater);
      return ResultResponse.success();
    });
  }

  @Override
  public ResultResponse<Map<Integer, Long>> getDiamondData(Long userId, Boolean isMonth) {
    return ResultResponse.success(salaryDiamondRunningWaterClientService.getDiamondData(userId, isMonth));
  }

  @Override
  public ResultResponse<Map<Long, Long>> getDiamondByUserIds(List<Long> userIds) {
    return ResultResponse.success(salaryDiamondRunningWaterClientService.getDiamondByUserIds(userIds));
  }

}
