package com.red.circle.order.inner.service.impl;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.order.infra.database.rds.entity.order.OrderOtherRecharge;
import com.red.circle.order.infra.database.rds.service.order.OrderOtherRechargeService;
import com.red.circle.order.inner.convertor.OrderOtherRechargeInnerConvertor;
import com.red.circle.order.inner.model.cmd.inapp.OrderOtherRechargePageQryCmd;
import com.red.circle.order.inner.model.dto.inapp.OrderOtherRechargeDTO;
import com.red.circle.order.inner.service.OrderOtherRechargeClientService;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 其他充值.
 *
 * @author pengliang on 2023/11/3
 */
@Service
@RequiredArgsConstructor
public class OrderOtherRechargeClientServiceImpl implements OrderOtherRechargeClientService {

  private final OrderOtherRechargeService orderOtherRechargeService;
  private final OrderOtherRechargeInnerConvertor orderOtherRechargeInnerConvertor;

  @Override
  public void add(OrderOtherRechargeDTO dto) {
    orderOtherRechargeService.save(orderOtherRechargeInnerConvertor.toOrderOtherRecharge(dto));
  }

  @Override
  public PageResult<OrderOtherRechargeDTO> pageOps(OrderOtherRechargePageQryCmd qryCmd) {
    return orderOtherRechargeService.query()
        .eq(Objects.nonNull(qryCmd.getUserId()), OrderOtherRecharge::getUserId, qryCmd.getUserId())
        .orderByDesc(OrderOtherRecharge::getId)
        .page(qryCmd.getPageQuery())
        .convert(orderOtherRechargeInnerConvertor::toOrderOtherRechargeDTO);
  }

}
