
package com.tmerclub.cloud.distribution.controller.platform;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.distribution.dto.DistributionUserWalletDTO;
import com.tmerclub.cloud.distribution.model.DistributionUserWallet;
import com.tmerclub.cloud.distribution.service.DistributionUserWalletService;
import com.tmerclub.cloud.distribution.vo.DistributionUserWalletVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分销员钱包信息
 *
 * @author cl
 * @date 2021-08-09 14:14:10
 */
@RestController("platformDistributionUserWalletController")
@RequestMapping("/p/distributionUserWallet")
@Tag(name = "分销员钱包信息")
public class DistributionUserWalletController {

    @Autowired
    private DistributionUserWalletService distributionUserWalletService;


    @GetMapping("/page")
    @Operation(summary = "获取分销员钱包信息列表", description = "分页获取分销员钱包信息列表")
    public ServerResponseEntity<PageVO<DistributionUserWallet>> page(@Valid PageDTO pageDTO) {
        PageVO<DistributionUserWallet> distributionUserWalletPage = distributionUserWalletService.page(pageDTO);
        return ServerResponseEntity.success(distributionUserWalletPage);
    }

    @GetMapping("/getWalletPage")
    @Operation(summary = "获取分销员钱包信息列表", description = "分页获取分销员钱包信息列表")
    public ServerResponseEntity<PageVO<DistributionUserWalletVO>> walletPage(@Valid PageDTO pageDTO, String userMobile) {
        PageVO<DistributionUserWalletVO> distributionUserWalletPage = distributionUserWalletService.walletPage(pageDTO, userMobile);
        return ServerResponseEntity.success(distributionUserWalletPage);
    }

    @GetMapping
    @Operation(summary = "获取分销员钱包信息", description = "根据walletId获取分销员钱包信息")
    public ServerResponseEntity<DistributionUserWallet> getByWalletId(@RequestParam Long walletId) {
        return ServerResponseEntity.success(distributionUserWalletService.getByWalletId(walletId));
    }

    @PutMapping
    @Operation(summary = "更新分销员钱包信息", description = "更新分销员钱包信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody DistributionUserWalletDTO distributionUserWalletDTO) {
        Long userId = AuthUserContext.get().getUserId();
        distributionUserWalletService.updateWallet(distributionUserWalletDTO, userId);
        return ServerResponseEntity.success();
    }

}
