package com.red.circle.order.inner.endpoint;

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.order.inner.endpoint.api.OrderPurchaseHistoryClientApi;
import com.red.circle.order.inner.model.cmd.UserRechargeDaysQryCmd;
import com.red.circle.order.inner.model.cmd.inapp.OrderPurchaseHistoryExportQryCmd;
import com.red.circle.order.inner.model.cmd.inapp.OrderPurchaseHistoryQryCmd;
import com.red.circle.order.inner.model.dto.OrderPurchaseHistoryDTO;
import com.red.circle.order.inner.service.OrderPurchaseHistoryClientService;
import java.math.BigDecimal;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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/11/3
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = OrderPurchaseHistoryClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
public class OrderPurchaseHistoryClientEndpoint implements OrderPurchaseHistoryClientApi {

  private final OrderPurchaseHistoryClientService orderPurchaseHistoryClientService;

  @Override
  public ResultResponse<Void> add(OrderPurchaseHistoryDTO order) {
    orderPurchaseHistoryClientService.add(order);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<PageResult<OrderPurchaseHistoryDTO>> pageQueryOps(
      OrderPurchaseHistoryQryCmd qryCmd) {
    return ResultResponse.success(orderPurchaseHistoryClientService.pageQueryOps(qryCmd));
  }

  @Override
  public ResultResponse<List<OrderPurchaseHistoryDTO>> exportOps(
      OrderPurchaseHistoryExportQryCmd qryCmd) {
    return ResultResponse.success(orderPurchaseHistoryClientService.exportOps(qryCmd));
  }

  @Override
  public ResultResponse<BigDecimal> purchaseTodayTotal() {
    return ResultResponse.success(orderPurchaseHistoryClientService.purchaseTodayTotal());
  }

  @Override
  public ResultResponse<BigDecimal> purchaseTodayTotalBySysOrigin(SysOriginPlatformEnum sysOrigin) {
    return ResultResponse.success(
        orderPurchaseHistoryClientService.purchaseTodayTotalBySysOrigin(sysOrigin));
  }

  @Override
  public ResultResponse<List<OrderPurchaseHistoryDTO>> purchaseTodayBySysOrigin(
      UserRechargeDaysQryCmd query) {
    return ResultResponse.success(
        orderPurchaseHistoryClientService.purchaseTodayBySysOrigin(query));
  }


  @Override
  public ResultResponse<BigDecimal> getPurchaseTotalByUserId(Long userId) {
    return ResultResponse.success(
        orderPurchaseHistoryClientService.getPurchaseTotalByUserId(userId));
  }

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

}
