package com.tashow.cloud.pay.api.order;

import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.pay.convert.order.PayOrderConvert;
import com.tashow.cloud.pay.dal.dataobject.order.PayOrderDO;
import com.tashow.cloud.pay.service.order.PayOrderService;
import com.tashow.cloud.payapi.api.order.PayOrderApi;
import com.tashow.cloud.payapi.api.order.dto.PayOrderCreateReqDTO;
import com.tashow.cloud.sdk.payment.dto.order.PayOrderRespDTO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import static com.tashow.cloud.common.pojo.CommonResult.success;


@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class PayOrderApiImpl implements PayOrderApi {

    @Resource
    private PayOrderService payOrderService;

    @Override
    public CommonResult<Long> createOrder(PayOrderCreateReqDTO reqDTO) {
        return success(payOrderService.createOrder(reqDTO));
    }

    @Override
    public CommonResult<PayOrderRespDTO> getOrder(Long id) {
        PayOrderDO order = payOrderService.getOrder(id);
        return success(PayOrderConvert.INSTANCE.convert2(order));
    }

    @Override
    public CommonResult<Boolean> updatePayOrderPrice(Long id, Integer payPrice) {
        payOrderService.updatePayOrderPrice(id, payPrice);
        return success(true);
    }

}
