package com.red.circle.order.infra.database.rds.service.order.impl;

import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl;
import com.red.circle.order.infra.database.rds.dao.order.OrderUserPurchasePayDAO;
import com.red.circle.order.infra.database.rds.entity.order.OrderUserPurchasePay;
import com.red.circle.order.infra.database.rds.service.order.OrderUserPurchasePayService;
import com.red.circle.tool.core.date.TimestampUtils;
import org.springframework.stereotype.Service;

/**
 * Web支付预下单服务实现.
 */
@Service
public class OrderUserPurchasePayServiceImpl
    extends BaseServiceImpl<OrderUserPurchasePayDAO, OrderUserPurchasePay>
    implements OrderUserPurchasePayService {

  private static final String PAY_STATUS_SUCCESSFUL = "SUCCESSFUL";
  private static final String PAY_STATUS_FAIL = "FAIL";

  @Override
  public void updateSuccess(Long id) {
    update()
        .set(OrderUserPurchasePay::getPayStatus, PAY_STATUS_SUCCESSFUL)
        .set(OrderUserPurchasePay::getReason, "")
        .set(OrderUserPurchasePay::getUpdateTime, TimestampUtils.now())
        .eq(OrderUserPurchasePay::getId, id)
        .execute();
  }

  @Override
  public void updateFail(Long id, String reason) {
    update()
        .set(OrderUserPurchasePay::getPayStatus, PAY_STATUS_FAIL)
        .set(OrderUserPurchasePay::getReason, reason)
        .set(OrderUserPurchasePay::getUpdateTime, TimestampUtils.now())
        .eq(OrderUserPurchasePay::getId, id)
        .execute();
  }
}
