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.dto.TransferAccountsDTO;
import com.fzm.mall.server.admin.finance_center.entity.dto.UserAssetsChangeDTO;
import com.fzm.mall.server.admin.finance_center.entity.vo.UserAssetsVO;
import com.fzm.mall.server.admin.finance_center.service.IMerchantAssetsFlowService;
import com.fzm.mall.server.admin.finance_center.service.IPlatformIntegralService;
import com.fzm.mall.server.admin.finance_center.service.IUserAssetService;
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.service.IAdminService;
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 javax.validation.Valid;
import java.util.List;

/**
 * @author wangp
 * @date 2021/4/27 10:44
 * @description 用户资产
 * @since JDK 1.8
 */
@Api(tags = "财务中心-用户资产")
@RestController
@RequestMapping("/userAsset")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserAssetController {
    private final IUserAssetService userAssetService;
    private final ResponseFactory resFac;
    private final IAdminService adminService;
    private final IPlatformIntegralService platformIntegralService;

    //TODO 商户资产 充值|扣除

    @ApiOperation(value = "分页查询-用户资产")
    @GetMapping("/page")
    public ResponseVO page(
            @ApiParam(name = "uid", value = "用户编号")
            @RequestParam(required = false) String uid,
            @ApiParam(name = "account", value = "用户登陆账号")
            @RequestParam(required = false) String account,
            @ApiParam(name = "type", value = "资产类型")
            @RequestParam(required = false) String type,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getPlatFormTypeArr());
        IPage<UserAssetsVO> page = userAssetService.page(uid, account, type, pageNum, pageSize);
        return resFac.getSuccessResponseWithData(page);
    }

    @ApiOperation(value = "资产类型")
    @GetMapping("/assetsType")
    public ResponseVO assetsType(@RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getPlatFormTypeArr());
        List<String> assetsTypes = userAssetService.assetsType();
        return resFac.getSuccessResponseWithData(assetsTypes);
    }

    @ApiOperation(value = "充值")
    @PostMapping("/recharge")
    public ResponseVO recharge(@RequestBody @Valid UserAssetsChangeDTO dto, @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getPlatFormTypeArr());
        platformIntegralService.recharge(dto);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "扣除")
    @PostMapping("/deduction")
    public ResponseVO deduction(@RequestBody @Valid UserAssetsChangeDTO dto, @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getPlatFormTypeArr());
        platformIntegralService.deduction(dto);
        return resFac.getSimpleSuccessResponse();
    }
}
