package com.izouma.nineth.web;

import com.izouma.nineth.domain.GiftOrder;
import com.izouma.nineth.domain.RechargeOrder;
import com.izouma.nineth.exception.BusinessException;
import com.izouma.nineth.repo.RechargeOrderRepo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/rechargeOrder")
@AllArgsConstructor
public class RechargeOrderController {

    private final RechargeOrderRepo rechargeOrderRepo;

    @GetMapping("/get/{id}")
    public RechargeOrder get(@PathVariable Long id) {
        return rechargeOrderRepo.findById(id).orElseThrow(new BusinessException("订单不存在"));
    }

    @GetMapping("/{id}/status")
    public Map<String, Object> status(@PathVariable Long id) {
        RechargeOrder order = rechargeOrderRepo.findById(id).orElseThrow(new BusinessException("订单不存在"));
        return new HashMap<>() {{
            put("status", order.getStatus());
        }};
    }
}
