package com.cool.store.controller.webb;

import com.cool.store.dto.close.CloseStoreMkUserDTO;
import com.cool.store.request.close.refund.CloseStoreRefundAddRequest;
import com.cool.store.request.close.refund.CloseStoreRefundQueryRequest;
import com.cool.store.request.close.refund.CloseStoreRefundSkipRequest;
import com.cool.store.request.close.refund.CloseStoreRefundUpdateRequest;
import com.cool.store.dto.xgj.XgjBranchBankDTO;
import com.cool.store.dto.xgj.XgjPartnerPageDTO;
import com.cool.store.request.close.refund.*;
import com.cool.store.request.xgj.XgjBankQueryRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.ThirdXgjService;
import com.cool.store.service.close.CloseStoreRefundService;
import com.cool.store.vo.close.refund.CloseStoreRefundDetailVO;
import com.cool.store.vo.close.refund.CloseStoreRefundListVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 闭店退款 前端控制器
 * </p>
 *
 * @author wangff
 * @since 2025/10/13
 */
@Api(tags = "闭店退款")
@RestController
@RequestMapping("/pc/close/refund")
@RequiredArgsConstructor
@Validated
public class CloseStoreRefundController {
    private final CloseStoreRefundService closeStoreRefundService;
    private final ThirdXgjService thirdXgjService;

    @ApiOperation("获取当前用户的每刻用户信息")
    @GetMapping("/getCurrentMkUser")
    public ResponseResult<CloseStoreMkUserDTO> getCurrentMkUser() {
        return ResponseResult.success(closeStoreRefundService.getCurrentMkUser());
    }

    @ApiOperation("获取退款详细信息")
    @GetMapping("/detail")
    @ApiImplicitParam(name = "id", value = "退款信息id", required = true, dataType = "Long")
    public ResponseResult<CloseStoreRefundDetailVO> detail(@NotNull(message = "退款信息id不能为空") Long id) {
        return ResponseResult.success(closeStoreRefundService.getRefundDetail(id));
    }

    @ApiOperation("新增退款信息")
    @PostMapping("/addRefund")
    public ResponseResult<Boolean> addRefund(@RequestBody @Valid CloseStoreRefundAddRequest request) {
        return ResponseResult.success(closeStoreRefundService.addRefund(request));
    }

    @ApiOperation("编辑退款信息")
    @PostMapping("/updateRefund")
    public ResponseResult<Boolean> updateRefund(@RequestBody @Valid CloseStoreRefundUpdateRequest request) {
        return ResponseResult.success(closeStoreRefundService.updateRefund(request));
    }

    @ApiOperation("跳过")
    @PostMapping("/skip")
    public ResponseResult<Boolean> skip(@RequestBody @Validated CloseStoreRefundSkipRequest request) {
        closeStoreRefundService.skip(request);
        return ResponseResult.success(true);
    }

    @ApiOperation("退款信息列表")
    @GetMapping("/refundPage")
    public ResponseResult<PageInfo<CloseStoreRefundListVO>> refundPage(@Validated CloseStoreRefundQueryRequest request) {
        return ResponseResult.success(closeStoreRefundService.refundPage(request));
    }

    @ApiOperation("退款状态刷新")
    @PostMapping("/refresh")
    public ResponseResult<Boolean> refresh(@RequestBody @Validated CloseStoreRefundQueryRequest request) {
        return ResponseResult.success(closeStoreRefundService.refreshRefundOrderStatus(request));
    }

    @ApiOperation("同步供应商")
    @PostMapping("/savePartner")
    public ResponseResult<Boolean> savePartner(@RequestBody @Validated CloseStorePartnerRequest request) {
        return ResponseResult.success(closeStoreRefundService.savePartner(request));
    }

    @ApiOperation("供应商列表")
    @PostMapping("/queryPartnerPage")
    public ResponseResult<XgjPartnerPageDTO> queryPartnerPage(@RequestBody CloseStorePartnerQueryRequest request) {
        return ResponseResult.success(closeStoreRefundService.queryPartnerPage(request));
    }

    @ApiOperation("支行列表")
    @PostMapping("/queryBranchBankList")
    public ResponseResult<List<XgjBranchBankDTO>> queryBranchBankList(@RequestBody XgjBankQueryRequest request) {
        return ResponseResult.success(closeStoreRefundService.queryBranchBankList(request));
    }
}
