package com.bohuikeji.delivery.backstage.controller.api.customer;

import com.bohuikeji.delivery.backstage.constants.WxAppEm;
import com.bohuikeji.delivery.backstage.entity.wx.TWxUser;
import com.bohuikeji.delivery.backstage.service.IWxUserService;
import com.bohuikeji.frame.module.admin.base.ApiController;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 周立武
 */
@Slf4j
@Api(tags = {"客户微信相关业务类"})
@RestController
@RequestMapping("/api/v2/customer/wx")
@RequiredArgsConstructor
public class CustomerWxV2Api extends ApiController {

    final IWxUserService wxUserService;

    @ApiOperation(value = "获取骑手公众号网页授权链接",notes = "返回一个链接地址，请使用web-view组件在微信内打开<br>待处理完成后跳转到小程序指定的页面")
    @GetMapping(value = "/customer/gzh/oauth/url")
    public APIEntity<String> getGzhOauthUrl(
            @RequestAttribute("JwtUserId") Integer id){
        return APIEntity.success(wxUserService.getGzhAutoUrl(id,WxAppEm.WX_USER_TYPE_CUSTOMER,"/open/wx/follow",WxAppEm.GZH_TCJS));
    }

    /**
     * 客户是否绑定公众号
     * @return
     */
    @GetMapping(value = "/customer/gzh/is/build")
    public APIEntity isBindGZh(@RequestAttribute("JwtUserId") Integer id){
        TWxUser user=wxUserService.getUserByType(id,WxAppEm.WX_USER_TYPE_CUSTOMER,WxAppEm.GZH_TCJS);
        if (user!=null){
            return APIEntity.success(true);
        }
        return APIEntity.success(false);
    }
}
