package org.dromara.app;

import com.wzj.soopin.transaction.convert.WithdrawConvert;
import com.wzj.soopin.transaction.domain.bo.WithdrawBO;
import com.wzj.soopin.transaction.enums.WithdrawType;
import com.wzj.soopin.transaction.service.IWithdrawService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.model.LoginUser;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.satoken.utils.LoginHelper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "租户")
@RestController
@RequestMapping("/app/tenant")
@RequiredArgsConstructor
public class AppTenantController {

    private final IWithdrawService withdrawService;
    private final WithdrawConvert withdrawConvert;
    @Operation(summary = "提现")
    @Log(title = "提现 ", businessType = BusinessType.INSERT)
    @PostMapping("/withdraw")
    public R withdraw(@RequestBody WithdrawBO bo) {
        //获取用户信息
        LoginUser loginUser = LoginHelper.getLoginUser();
        if (loginUser == null) {
            throw new ServiceException("用户未登录");
        }
        Long memberId = loginUser.getUserId();
        bo.setMemberId(memberId);
        bo.setType(WithdrawType.REVENUE.getCode());
        return R.ok(withdrawService.withdrawRevenue(withdrawConvert.toPo(bo)));
    }


}
