package com.zhongshu.card.server.core.controller.pay.withdraw;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.types.payment.PaymentType;
import com.zhongshu.card.client.model.pay.ProcessWithdrawParam;
import com.zhongshu.card.client.model.pay.WithdrawMonthPageParam;
import com.zhongshu.card.client.model.pay.WithdrawPageParam;
import com.zhongshu.card.client.model.pay.WithdrawParam;
import com.zhongshu.card.server.core.service.pay.WithdrawService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("withdraw")
@Tag(name = "机构资金-提现", description = "机构资金-提现")
public class WithdrawController {

    @Autowired
    private WithdrawService withdrawService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询项目下所有账户可提案余额", description = "查询项目下所有账户可提案余额")
    @RequestMapping(value = "queryProjectWithdrawAmount", method = RequestMethod.GET)
    public Object queryProjectWithdrawAmount(@RequestParam(value = "projectId", required = false) String projectOid) {
        return withdrawService.queryWithdrawAmount(projectOid);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询账户可提案余额", description = "顶部数据及资金概况-折线图")
    @RequestMapping(value = "queryWithdrawAmount", method = RequestMethod.GET)
    public Object queryWithdrawAmount(@RequestParam(value = "projectId", required = false) String projectOid,
            @RequestParam(value = "oid", required = false) String oid) {
        return withdrawService.queryWithdrawAmount(projectOid, oid);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询渠道可提案余额", description = "顶部数据及资金概况-折线图")
    @RequestMapping(value = "queryWithdrawAmountByPayment", method = RequestMethod.GET)
    public Object queryWithdrawAmountByPayment(@RequestParam(value = "projectId", required = false) String projectOid,
            @RequestParam(value = "oid", required = false) String oid,
            @RequestParam("paymentType") PaymentType paymentType) {
        return withdrawService.queryWithdrawAmount(projectOid, oid, paymentType);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "发起提现", description = "发起提现")
    @RequestMapping(value = "withdrawApply", method = RequestMethod.POST)
    public Object withdrawApply(@RequestBody WithdrawParam param) {
        return withdrawService.withdrawApply(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "审核提现", description = "审核提现")
    @RequestMapping(value = "withdraw", method = RequestMethod.POST)
    public Object withdraw(@RequestBody ProcessWithdrawParam param) {
        return withdrawService.withdraw(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "分页查询-提现记录", description = "查询提现记录")
    @RequestMapping(value = "page", method = RequestMethod.POST)
    public Object page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) WithdrawPageParam param) {
        return withdrawService.page(pageable, param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询提现状态", description = "查询提现状态")
    @RequestMapping(value = "withdrawQuery", method = RequestMethod.GET)
    public Object withdrawQuery(@RequestParam("id") String id) {
        return withdrawService.withdrawQuery(id);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询提现订单详情", description = "查询提现状态")
    @RequestMapping(value = "queryDetailById", method = RequestMethod.GET)
    public Object queryDetailById(@RequestParam("id") String id) {
        return withdrawService.queryDetailById(id);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "按月分页查询-提现记录", description = "按月分页查询-提现记录")
    @RequestMapping(value = "monthPage", method = RequestMethod.POST)
    public Object monthPage(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
                            @Parameter(required = false) WithdrawMonthPageParam param){
        return withdrawService.page(pageable, param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询提现余额明细", description = "查询提现余额明细")
    @RequestMapping(value = "transactionLogPage", method = RequestMethod.POST)
    public Object transactionLogPage(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
                                     @Parameter(required = false) WithdrawMonthPageParam param){
        return withdrawService.transactionLogPage(pageable, param);
    }
}
