package com.yn.bftl.thirdparty.modules.business.controller.member;

import com.yn.bftl.thirdparty.modules.business.service.SubaccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * 分账控制层
 *
 * @author huabiao
 * @create 2022/9/19  19:31
 **/
@Validated
@Api(value = "SubaccountMemberController", tags = "用户端-分账")
@RestController
@RequestMapping("/member/subaccount")
public class SubaccountMemberController {

    @Resource
    private SubaccountService subaccountService;

    @ApiOperation(value = "分账-生成临时结算单")
    @RequestMapping(value = "/temp_statement/create", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单ID", dataType = "Long", dataTypeClass = Long.class, required = true)
    })
    public void generateTemporaryStatement(@NotNull Long orderId) {
        subaccountService.generateTemporaryStatement(orderId);
    }

    @ApiOperation(value = "分账-生成结算单(根据订单)")
    @RequestMapping(value = "/statement/create_by_order", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单ID", dataType = "Long", dataTypeClass = Long.class, required = true)
    })
    public void generateStatementByOrder(@NotNull Long orderId) {
        subaccountService.generateStatementByOrder(orderId);
    }

    @ApiOperation(value = "分账-生成结算单(根据发货单)")
    @RequestMapping(value = "/statement/create_by_shipping", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "shippingId", value = "发货单ID", dataType = "Long", dataTypeClass = Long.class, required = true)
    })
    public void generateStatementByShipping(@NotNull Long shippingId) {
        subaccountService.generateStatementByShipping(shippingId);
    }

    @ApiOperation(value = "分账-生成结算单(根据售后单)")
    @RequestMapping(value = "/statement/create_by_afterSale", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "afterSaleId", value = "售后单ID", dataType = "Long", dataTypeClass = Long.class, required = true)
    })
    public void generateStatementByAfterSale(@NotNull Long afterSaleId) {
        subaccountService.generateStatementByAfterSale(afterSaleId);
    }

    @ApiOperation(value = "分账-生成分账单(根据订单)")
    @RequestMapping(value = "/create_by_order", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单ID", dataType = "Long", dataTypeClass = Long.class, required = true)
    })
    public void generateSubaccountByOrder(@NotNull Long orderId) {
        subaccountService.generateSubaccountByOrder(orderId);
    }

    @ApiOperation(value = "分账-生成分账单(根据发货单)")
    @RequestMapping(value = "/create_by_shipping", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "shippingId", value = "发货单ID", dataType = "Long", dataTypeClass = Long.class, required = true)
    })
    public void generateSubaccountByShipping(@NotNull Long shippingId) {
        subaccountService.generateSubaccountByShipping(shippingId);
    }

    @ApiOperation(value = "品牌授权费-处理")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "subaccountNo", value = "分账单号", dataType = "String", dataTypeClass = String.class, required = true)
    })
    @RequestMapping(value = "/handle_brandAuthFee", method = RequestMethod.POST)
    public void handleBrandAuthFee(@NotBlank String subaccountNo) {
        subaccountService.handleBrandAuthFee(subaccountNo);
    }

    @ApiOperation(value = "分账-生成退款结算单(根据订单订单)")
    @RequestMapping(value = "/statement/create_by_order_refund", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "退款单ID", dataType = "Long", dataTypeClass = Long.class, required = true)
    })
    public void generateStatementByOrderRefund(@NotNull Long orderId) {
        subaccountService.generateStatementByOrderRefund(orderId);
    }

    @ApiOperation(value = "货款-处理差额")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "subaccountNo", value = "分账单号", dataType = "String", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(paramType = "query", name = "orderItemIdList", value = "订单项ID", dataType = "ArrayList", dataTypeClass = ArrayList.class),
    })
    @RequestMapping(value = "/handle_goodsCost", method = RequestMethod.POST)
    public void handleGoodsCost(@NotBlank String subaccountNo, @RequestParam List<Long> orderItemIdList) {
        subaccountService.handleGoodsCost(subaccountNo, orderItemIdList);
    }

}
