package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.request.*;
import com.cool.store.response.AdjustmentOrderResponse;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.AdjustmentOrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 费用调整单 Controller
 */
@RequestMapping("/pc/adjustmentOrder")
@RestController
@Api(tags = "费用调整单管理")
@Slf4j
public class AdjustmentOrderController {

    @Resource
    private AdjustmentOrderService adjustmentOrderService;

    @PostMapping("/add")
    @ApiOperation("新增费用调整单")
    public ResponseResult<Boolean> add(@Valid @RequestBody AdjustmentOrderRequest request) {
        return ResponseResult.success(adjustmentOrderService.add(request));
    }

    @PostMapping("/update")
    @ApiOperation("编辑费用调整单")
    public ResponseResult<Boolean> update(@Valid @RequestBody AdjustmentOrderRequest request) {
        return ResponseResult.success(adjustmentOrderService.update(request));
    }

    @PostMapping("/recognizePayment")
    @ApiOperation("认领")
    public ResponseResult<Boolean> recognizePayment(@Valid @RequestBody RecognizePaymentRequest request) {
        return ResponseResult.success(adjustmentOrderService.recognizePayment(request, CurrentUserHolder.getUser()));
    }

    @PostMapping("/delete")
    @ApiOperation("删除费用调整单")
    public ResponseResult<Boolean> delete(@ApiParam("调整单ID") @RequestParam Long id) {
        return ResponseResult.success(adjustmentOrderService.delete(id));
    }

    @GetMapping("/getById")
    @ApiOperation("根据ID查询费用调整单详情")
    public ResponseResult<AdjustmentOrderResponse> getById(@ApiParam("调整单ID") @RequestParam Long id) {
        return ResponseResult.success(adjustmentOrderService.getById(id));
    }

    @PostMapping("/page")
    @ApiOperation("分页查询费用调整单")
    public ResponseResult<PageInfo<AdjustmentOrderResponse>> page(@RequestBody AdjustmentOrderPageRequest request) {
        return ResponseResult.success(adjustmentOrderService.page(request));
    }

    @PostMapping("/getSpecialStatusData")
    @ApiOperation("选择关联费用单费用调整单列表")
    public ResponseResult<PageInfo<AdjustmentOrderResponse>> getSpecialStatusData(@RequestBody AdjustmentSpecialPageRequest request) {
        return ResponseResult.success(adjustmentOrderService.getSpecialStatusData(request));
    }


    @PostMapping("/generateSplitOrder")
    @ApiOperation("生成分账单")
    public ResponseResult<String> generateSplitOrder(@Valid @RequestBody GenerateSplitOrderRequest request) {
        return ResponseResult.success(adjustmentOrderService.generateSplitOrder(request));
    }
}
