package com.gree.mall.miniapp.controller.material.withdrawal;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.miniapp.bean.material.settlement.SettlementAmountBean;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.material.withdrawal.WithdrawalLogic;
import com.gree.mall.miniapp.plus.entity.WithdrawalOrder;
import com.gree.mall.miniapp.plus.entity.WithdrawalOrderItem;
import com.gree.mall.miniapp.plus.entity.WorkerBank;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Api(value = "师傅提现API", tags ={"师傅提现API"} )
@RequestMapping(value = "/withdrawal", produces = "application/json; charset=utf-8")
public class WithdrawalController {

    @Autowired
    WithdrawalLogic withdrawalLogic;

    @PostMapping("/save")
    @ApiOperation(value = "申请提现")
    public ResponseHelper save(
           @ApiParam(value = "银行卡id",required = true) @RequestParam String workerBankId
    ) throws RemoteServiceException {
        withdrawalLogic.add(workerBankId);
        return ResponseHelper.success();
    }

    @PostMapping("/detail")
    @ApiOperation(value = "申请提现-详情")
    public ResponseHelper<WithdrawalOrder> detail(
            @ApiParam(value = "id",required = true) @RequestParam String id
    ) throws RemoteServiceException {
        WithdrawalOrder detail = withdrawalLogic.detail(id);
        return ResponseHelper.success(detail);
    }

    @PostMapping("/amount/count")
    @ApiOperation(value = "销售收益统计")
    public ResponseHelper<SettlementAmountBean> totalAmount() throws RemoteServiceException {
        SettlementAmountBean settlementAmountBean = withdrawalLogic.totalAmount();
        return ResponseHelper.success(settlementAmountBean);
    }


    @PostMapping("/list")
    @ApiOperation("提现订单")
    public ResponseHelper<IPage<WithdrawalOrder>> list(
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize
    ){
        IPage<WithdrawalOrder> list = withdrawalLogic.list(startTime,endTime,pageNum, pageSize);
        return ResponseHelper.success(list);
    }

    @PostMapping("/list/detail")
    @ApiOperation("提现订单明细")
    public ResponseHelper<IPage<WithdrawalOrderItem>> list(
            @RequestParam String id,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize
    ){
        IPage<WithdrawalOrderItem> list = withdrawalLogic.listDetail(id,pageNum, pageSize);
        return ResponseHelper.success(list);
    }






}
