package com.hys.app.controller.erp.use;

import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dto.OrderReturnQueryParams;
import com.hys.app.model.erp.dto.OrderReturnStatisticsQueryParam;
import com.hys.app.model.erp.enums.OrderReturnStatusEnum;
import com.hys.app.model.erp.vo.OrderReturnVO;
import com.hys.app.model.erp.dto.OrderReturnDTO;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.service.erp.OrderReturnManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 订单退货API
 *
 * @author 张崧
 * @since 2023-12-14 15:42:07
 */
@RestController
@RequestMapping("/admin/erp/orderReturn")
@Api(tags = "订单退货API")
@Validated
public class OrderReturnManagerController {

    @Autowired
    private OrderReturnManager orderReturnManager;

    @ApiOperation(value = "分页列表")
    @GetMapping
    public WebPage<OrderReturnVO> list(OrderReturnQueryParams queryParams) {
        return orderReturnManager.list(queryParams);
    }

    @ApiOperation(value = "添加")
    @PostMapping
    @Log(client = LogClient.admin, detail = "创建订单退货单")
    public void add(@RequestBody @Valid OrderReturnDTO orderReturnDTO) {
        orderReturnManager.add(orderReturnDTO);
    }

    @ApiOperation(value = "关闭订单/完成订单")
    @PostMapping("/cancel/{edit}/{id}")
    @Log(client = LogClient.admin, detail = "关闭ID为[${id}]的订单退货单")
    public void withdraw(@PathVariable String edit,@PathVariable Long id) {
        orderReturnManager.cancel(edit,id);
    }

    @ApiOperation(value = "查询")
    @GetMapping("/{id}")
    public OrderReturnVO getDetail(@PathVariable String id) {
        return orderReturnManager.getDetail(id);
    }

    @ApiOperation(value = "查询订单退货统计分页列表数据")
    @GetMapping("/statistics")
    public WebPage statistics(OrderReturnStatisticsQueryParam params) {
        return orderReturnManager.statistics(params);
    }

    @ApiOperation(value = "导出订单退货统计列表数据")
    @GetMapping("/export")
    public void export(HttpServletResponse response, OrderReturnStatisticsQueryParam params) {
        this.orderReturnManager.export(response, params);
    }
}

