package cn.iocoder.yudao.module.member.controller.app.wxstoreorder;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.member.controller.admin.wxstoreorder.vo.WxStoreOrderPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.wxstoreorder.vo.WxStoreOrderRespVO;
import cn.iocoder.yudao.module.member.controller.admin.wxstoreorder.vo.WxStoreOrderSaveReqVO;
import cn.iocoder.yudao.module.member.controller.app.wxstoreorder.vo.WxStoreOrderVO;
import cn.iocoder.yudao.module.member.dal.dataobject.wxstoreorder.WxStoreOrderDO;
import cn.iocoder.yudao.module.member.service.wxstoreorder.WxStoreOrderService;
import cn.iocoder.yudao.module.system.api.carteen.CarteenApi;
import cn.iocoder.yudao.module.system.api.carteen.dto.CarteenRespDto;
import cn.iocoder.yudao.module.system.api.cashregisterinfo.CashregisterinfoApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "APP - 微信付款码订单")
@RestController
@RequestMapping("/member/wx-store-order")
@Validated
public class AppWxStoreOrderController {

    @Resource
    private WxStoreOrderService wxStoreOrderService;
    @Resource
    private CashregisterinfoApi cashregisterinfoApi;
    @Resource
    private CarteenApi carteenApi;

    @PostMapping("/wxPay")
    public CommonResult<Boolean> wxPay(@RequestBody WxStoreOrderVO vo, HttpServletRequest request) {
        String equipment = request.getHeader("Authorization");
        Long storeId = cashregisterinfoApi.getStoreId(equipment);
        CarteenRespDto carteen = carteenApi.getCarteenById(storeId);
        vo.setCarteenId(carteen.getId());
        vo.setCarteenName(carteen.getStoresName());
        Boolean b = wxStoreOrderService.wxPay(vo);
        return success(b,b?"支付成功":"支付失败");
    }

}