package com.fzm.mall.server.admin.finance_center.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fzm.mall.server.admin.finance_center.entity.vo.IntegralListVO;
import com.fzm.mall.server.admin.finance_center.entity.vo.MerchantAssetsFlowVO;
import com.fzm.mall.server.admin.finance_center.service.IMerchantAssetsFlowService;
import com.fzm.mall.server.admin.finance_center.service.IMerchantAssetsService;
import com.fzm.mall.server.admin.finance_center.service.IMerchantIntegralService;
import com.fzm.mall.server.admin.finance_center.service.IPlatformIntegralService;
import com.fzm.mall.server.admin.home_page.enums.type.AdminTypeEnum;
import com.fzm.mall.server.admin.home_page.model.Admin;
import com.fzm.mall.server.admin.home_page.model.Merchant;
import com.fzm.mall.server.admin.home_page.service.IAdminService;
import com.fzm.mall.server.admin.home_page.service.IMerchantService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wangp
 * @date 2021/4/27 10:44
 * @description 商户流水
 * @since JDK 1.8
 */
@Api(tags = "财务中心-商户流水")
@RestController
@RequestMapping("/merchantAssetsFlow")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MerchantAssetsFlowController {
    private final IMerchantAssetsFlowService merchantAssetsFlowService;
    private final ResponseFactory resFac;
    private final IAdminService adminService;
    private final IMerchantAssetsService merchantAssetsService;

    @ApiOperation(value = "分页查询-商户流水")
    @GetMapping("/page")
    public ResponseVO page(
            @ApiParam(name = "flowId", value = "流水号")
            @RequestParam(required = false) String flowId,
            @ApiParam(name = "merchantId", value = "商户编号")
            @RequestParam(required = false) String merchantId,
            @ApiParam(name = "coin", value = "资产类型")
            @RequestParam(required = false) String coin,
            @ApiParam(name = "type", value = "记录类型")
            @RequestParam(required = false) Integer type,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestHeader String adminId) {
        Admin admin = adminService.getByAdminId(adminId);
        if (admin.getType().equals(AdminTypeEnum.MERCHANT.getType()) || admin.getType().equals(AdminTypeEnum.PLATFORM_MERCHANT.getType())) {
            merchantId = admin.getMerchantId();
        }
        IPage<MerchantAssetsFlowVO> page = merchantAssetsFlowService.page(flowId, merchantId, coin, type, pageNum, pageSize);
        return resFac.getSuccessResponseWithData(page);
    }

    @ApiOperation(value = "资产类型")
    @GetMapping("/assetsType")
    public ResponseVO assetsType() {
        List<String> assetsTypes = merchantAssetsService.assetsType();
        return resFac.getSuccessResponseWithData(assetsTypes);
    }
}
