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

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.model.pay.PeriodDetailQueryModel;
import com.zhongshu.card.client.model.pay.PeriodQueryModel;
import com.zhongshu.card.client.model.pay.SettleDetailQueryModel;
import com.zhongshu.card.server.core.service.pay.OrgOverviewService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("fundOverview")
@Tag(name = "资金概况", description = "资金概况")
public class PayOverviewController {

    @Autowired
    OrgOverviewService orgOverviewService;

//    @Operation(summary = "余额概况", description = "资金概况-顶部三个余额")
//    @RequestMapping(value = "balanceOverview", method = RequestMethod.GET)
//    public Object balanceOverview(@RequestParam(name = "projectOid", required = false) String projectOid,
//                                  @RequestParam(name = "oid" ,required = false) String oid){
//        return orgOverviewService.balanceOverview(projectOid, oid);
//    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "实时概况", description = "顶部数据及资金概况-折线图")
    @RequestMapping(value = "realTimeOverview", method = RequestMethod.GET)
    public Object realTimeOverview(@RequestParam(name = "projectOid", required = false) String projectOid,
                                  @RequestParam(name = "oid" ,required = false) String oid){
        return orgOverviewService.realTimeOverview(projectOid);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询收入账单", description = "查询收入账单-年月日汇总")
    @RequestMapping(value = "queryCreditBill", method = RequestMethod.POST)
    public Object queryCreditBill(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10)Pageable pageable,
                                  @Parameter(required = true) PeriodQueryModel param){
        return orgOverviewService.queryCreditBill(pageable, param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询收入账单详情", description = "查询收入账单详情")
    @RequestMapping(value = "queryCreditBillDetail", method = RequestMethod.POST)
    public Object queryCreditBillDetail(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
                                        @Parameter(required = true) PeriodDetailQueryModel periodDetailQueryModel){
        return orgOverviewService.queryCreditBillDetail(pageable, periodDetailQueryModel);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @RequestMapping(value = "exportCreditBill", method = RequestMethod.POST)
    @Operation(summary = "下载收入账单", description = "下载收入账单")
    public void exportCreditBill(HttpServletRequest request, HttpServletResponse response, @RequestBody PeriodDetailQueryModel periodDetailQueryModel){
        orgOverviewService.exportCreditBill(request, response, periodDetailQueryModel);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询结算账单", description = "查询结算账单")
    @RequestMapping(value = "querySettleBill", method = RequestMethod.POST)
    public Object querySettleBill(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
                                  @Parameter(required = false) PeriodQueryModel param){
        return orgOverviewService.querySettleBill(pageable, param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询结算账单详情", description = "查询结算账单详情")
    @RequestMapping(value = "querySettleBillDetail", method = RequestMethod.POST)
    public Object querySettleBillDetail(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
                                        @Parameter(required = false) SettleDetailQueryModel settleDetailQueryModel){
        return orgOverviewService.querySettleBillDetail(pageable, settleDetailQueryModel);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "下载结算账单", description = "下载结算账单")
    @RequestMapping(value = "exportSettleBill", method = RequestMethod.POST)
    public void exportSettleBill(HttpServletRequest request, HttpServletResponse response, @RequestBody SettleDetailQueryModel settleDetailQueryModel){
        orgOverviewService.exportSettleBill(request, response, settleDetailQueryModel);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询提现账单", description = "查询提现账单")
    @RequestMapping(value = "queryWithdrawBill", method = RequestMethod.POST)
    public Object queryWithdrawBill(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
                                  @Parameter(required = false) PeriodQueryModel param){
        return orgOverviewService.queryWithdrawBill(pageable, param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "查询提现账单详情", description = "查询提现账单详情")
    @RequestMapping(value = "queryWithdrawBillDetail", method = RequestMethod.POST)
    public Object queryWithdrawBillDetail(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
                                        @Parameter(required = false) SettleDetailQueryModel settleDetailQueryModel){
        return orgOverviewService.queryWithdrawBillDetail(pageable, settleDetailQueryModel);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "下载提现账单", description = "下载提现账单")
    @RequestMapping(value = "exportWithdrawBill", method = RequestMethod.POST)
    public void exportWithdrawBill(HttpServletRequest request, HttpServletResponse response, @RequestBody SettleDetailQueryModel settleDetailQueryModel){
        orgOverviewService.exportWithdrawBill(request, response, settleDetailQueryModel);
    }
}
