package com.seer.teach.pay.app.wallet.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.pay.app.wallet.convert.UserCoinAccountConvert;
import com.seer.teach.pay.app.wallet.resp.UserCoinAccountResp;
import com.seer.teach.pay.app.wallet.service.IAppUserCoinAccountService;
import com.seer.teach.pay.entity.PayCoinAccountEntity;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "APP - 钱包")
@Validated
@RequiredArgsConstructor
@RequestMapping("/app/wallet")
@SaCheckLogin(type = StpUtil.TYPE)
public class AppUserCoinAccountController {

    private final IAppUserCoinAccountService userCoinAccountService;

    @Operation(summary = "我的账户")
    @GetMapping("/my-account")
    @DecryptionAnnotation
    @EncryptionAnnotation
    @SaCheckPermission("app:wallet:account:view")
    public ResultBean<UserCoinAccountResp> getUserCoinAccount() {
        PayCoinAccountEntity account = userCoinAccountService.getByUserId(StpUtil.getLoginIdAsInt());
        return ResultBean.success(UserCoinAccountConvert.INSTANCE.convert( account));
    }

}