package com.bonus.canteen.core.account.v4.app.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.canteen.core.account.v4.app.dto.AppAccInfoV4DTO;
import com.bonus.canteen.core.account.v4.app.dto.AppTradeV4PageDTO;
import com.bonus.canteen.core.account.v4.app.dto.PaymentDto;
import com.bonus.canteen.core.account.v4.app.service.PaymentStageService;
import com.bonus.canteen.core.account.v4.app.service.impl.AppAccV4Service;
import com.bonus.canteen.core.account.v4.app.vo.AppSubsidyTradeVO;
import com.bonus.canteen.core.common.page.PageVO;
import com.bonus.canteen.core.common.utils.HeaderFetchUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping({"/api/v4/app/account"})
@Api(
        value = "账户管理/移动端/v4",
        tags = {"账户管理/移动端/v4"}
)
public class AppAccV4Controller extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(AppAccV4Controller.class);
    @Resource
    private AppAccV4Service appAccV4Service;
    @Resource
    private PaymentStageService paymentStageService;

    @ApiOperation(
            value = "查询账户(仅返回钱包余额)",
            notes = "移动端查询账户(仅返回钱包余额)"
    )
    @PostMapping({"/wallet/balance"})
    public AjaxResult queryWalletBalance(@RequestBody AppAccInfoV4DTO o) {
        return success(this.appAccV4Service.queryWalletBalance(o));
    }

    @ApiOperation(
            value = "查询账户(基础信息+余额)",
            notes = "移动端查询账户(基础信息+余额)"
    )
    @PostMapping({"/info"})
    public AjaxResult queryAccInfoForApp(@RequestBody AppAccInfoV4DTO o) {
        return success(this.appAccV4Service.queryAccInfoForApp(o));
    }

    @ApiOperation(
            value = "查询补贴(钱包)交易明细",
            notes = "查询补贴(钱包)交易明细"
    )
    @PostMapping({"/subsidy/trade/list"})
    public PageVO<AppSubsidyTradeVO> queryAccSubsidyTradeForApp(@RequestHeader Map<String, String> headers,
                                                                @RequestBody @Valid AppTradeV4PageDTO content) {
        content.setOpenid(HeaderFetchUtil.getOpenid(headers));
        content.setSourceType(HeaderFetchUtil.getSourceType(headers));
        return this.appAccV4Service.queryAccSubsidyTradeForApp(content);
    }

    @ApiOperation(
            value = "驿站支付",
            notes = "驿站支付"
    )
    @PostMapping({"/payMoneyForStage"})
    public AjaxResult payMoneyForStage(@RequestBody PaymentDto dto) {
        return this.paymentStageService.payMoneyForStage(dto);
    }
    @ApiOperation(
            value = "驿站退款",
            notes = "驿站退款"
    )
    @PostMapping({"/refundMoneyForStage"})
    public AjaxResult refundMoneyForStage(@RequestBody PaymentDto dto) {
        return this.paymentStageService.refundMoneyForStage(dto);
    }
}
