package org.dromara.main.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.main.domain.bo.RefundBo;
import org.dromara.main.domain.vo.RefundVo;
import org.dromara.main.service.IRefundService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 退款管理Controller
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping({"/system/refund", "/main/refund"})
public class RefundController extends BaseController {

    private final IRefundService refundService;

    @Log(title = "退款管理", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R<Long> createRefund(@Valid @RequestBody RefundBo bo) {
        Long refundId = refundService.createRefund(
            bo.getOrderId(),
            bo.getRefundAmount(),
            bo.getRefundReason(),
            bo.getOperatorId(),
            bo.getOperatorName()
        );
        return R.ok(refundId);
    }

    @GetMapping("/list/{orderId}")
    public R<List<RefundVo>> listByOrderId(@PathVariable Long orderId) {
        return R.ok(refundService.queryByOrderId(orderId));
    }

    @GetMapping("/{id}")
    public R<RefundVo> getInfo(@PathVariable Long id) {
        return R.ok(refundService.queryById(id));
    }
}
