package com.leromro.core.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.leromro.core.domain.dto.VolunteerSubmitAmountDTO;
import com.leromro.core.facade.VolunteerAccountFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.leromro.common.core.domain.R;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.leromro.common.annotation.Log;
import com.leromro.common.core.controller.BaseController;
import com.leromro.common.core.domain.AjaxResult;
import com.leromro.common.enums.BusinessType;
import com.leromro.core.domain.VolunteerAccount;
import com.leromro.core.service.IVolunteerAccountService;
import com.leromro.common.utils.poi.ExcelUtil;
import com.leromro.common.core.page.TableDataInfo;

/**
 * 志愿者账户Controller
 *
 * @author ruoyi
 * @date 2025-04-11
 */
@RestController
@Api(tags = "志愿者账户")
@RequestMapping("/core/volunteer/account")
public class VolunteerAccountController extends BaseController {
    @Autowired
    private IVolunteerAccountService volunteerAccountService;

    @Autowired
    private VolunteerAccountFacade volunteerAccountFacade;

//    /**
//     * 查询志愿者账户列表
//     */
//    @ApiOperation("查询志愿者账户列表")
//    @GetMapping("/list")
//    public TableDataInfo<VolunteerAccount> list(VolunteerAccount volunteerAccount)
//    {
//        startPage();
//        List<VolunteerAccount> list = volunteerAccountService.selectVolunteerAccountList(volunteerAccount);
//        return getDataTable(list);
//    }


    /**
     * 获取志愿者账户详细信息
     */
    @ApiOperation("获取志愿者账户详细信息")
    @GetMapping("/getVolunteerAccountInfo")
    public R<VolunteerAccount> getVolunteerAccountInfo() {
        return R.ok(volunteerAccountService.getOne(new LambdaQueryWrapper<VolunteerAccount>()
                .eq(VolunteerAccount::getVolunteerId, getUserId())));
    }

    /**
     * 提交提现申请
     */
    @PostMapping({"/submitAmountApply"})
    @ApiOperation(value = "提交提现申请", notes = "提交提现申请", produces = "application/json")
    public R submitAmountApply(@RequestBody @Validated VolunteerSubmitAmountDTO dto) {
        if (dto.getPayType().equals("1")) {
            return R.fail("暂不支持银行卡提现");
        } else if (dto.getPayType().equals("2")) {
            if (StrUtil.isBlank(dto.getAlipayAccountNo())) {
                return R.fail("支付宝账户不能为空");
            }
            if (StrUtil.isBlank(dto.getAlipayAccountNo())) {
                return R.fail("支付宝名称不能为空");
            }
        }
        return volunteerAccountFacade.submitAmountApply(dto);
    }

    /**
     * 获取当前用户提现状态
     */
    @GetMapping({"/getWithdrawStatus"})
    @ApiOperation(value = "获取当前用户提现状态", notes = "返回200允许填写，返回500直接提示", produces = "application/json")
    public R getWithdrawStatus() {
        return volunteerAccountFacade.getWithdrawStatus();
    }




}
