package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.WebAudit;
import shop.alien.entity.store.vo.WebAuditVo;
import shop.alien.store.service.WebAuditService;

import java.util.List;

/**
 * @Author: fcw
 * @CreateTime: 2025-04-01
 * @Description: 审核
 */
@Api(tags = {"审核"})
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/webAudit")
@RequiredArgsConstructor
public class WebAuditController {

    private final WebAuditService webAuditService;

    @ApiOperation("审核列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "size", value = "页容", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "type", value = "类型", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/getAuditList")
    public R<IPage<WebAudit>> getAuditList(@RequestParam(value = "page", defaultValue = "1") int page,
                                           @RequestParam(value = "size", defaultValue = "10") int size,
                                           @RequestParam(value = "status", defaultValue = "0") String status,
                                           @RequestParam("type") String type) {
        log.info("LifeStoreOrderController.getOrderListByStatus?page={},size={},storeId={},status={}", page, size, status, type);
        return R.data(webAuditService.getOrderList(page, size, status, type));
    }

    @ApiOperation("统计待处理")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/getAuditSum")
    public R<List<WebAuditVo>> getAuditSum() {
        log.info("LifeStoreOrderController.getOrderListByStatus");
        return R.data(webAuditService.getAuditSum());
    }

    @ApiOperation("平台处理审核退款等埋点")
    @PostMapping("/platformAuditRefundTrack")
    public R platformAuditRefundTrack(@RequestBody WebAudit webAudit) {
        return webAuditService.platformAuditRefundTrack(webAudit) > 0 ? R.success("成功") : R.fail("失败");
    }

}
