package com.liquidnet.service.sweet.controller;

import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.sweet.service.impl.SweetWechatMaoDengServiceImpl;
import com.liquidnet.service.sweet.utils.QueueUtils;
import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils;
import com.liquidnet.service.sweet.vo.SweetMaoDengVo;
import com.liquidnet.service.sweet.vo.SweetWechatUsersVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "活动-猫登活动")
@RestController
@RequestMapping("/wechatMaoDeng")
@Slf4j
public class SweetWechatMaoDengController {

    @Autowired
    private WechatUsersRedisUtils redisUtils;
    @Autowired
    QueueUtils queueUtils;
    @Autowired
    private SweetWechatMaoDengServiceImpl sweetWechatMaoDengService;


    @GetMapping("/backData")
    @ApiOperation("返回文字图片")
    public ResponseDto<SweetMaoDengVo> backDatas(String userId, String maoId) {
        SweetWechatUsersVo wechatUsers = redisUtils.getSweetWechatUsersOfUnionId(userId, 2);
        if (null == wechatUsers) {
            return ResponseDto.failure("获取信息失败");
        }
        SweetMaoDengVo sweetMaoDeng = redisUtils.getSweetMaoDeng(wechatUsers.getOpenId());
        if (sweetMaoDeng != null) {
            String textMsg = sweetMaoDeng.getTextMsg();
            String image = sweetMaoDeng.getPicUrl();
            if (StringUtil.isEmpty(textMsg) && StringUtil.isEmpty(image)) {
                return ResponseDto.failure("90081", "获取信息失败");
            }

            return ResponseDto.success(sweetMaoDeng);
        }
        return ResponseDto.failure("获取信息失败");
    }

    @PostMapping("/backData")
    @ApiOperation("存生成的图")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", dataType = "String", name = "userId", value = "userId"),
            @ApiImplicitParam(type = "query", dataType = "String", name = "imgUrl", value = "imgUrl"),
    })
    public ResponseDto addBuilderImg(@RequestParam(value = "userId", required = false) String userId,
                                     @RequestParam(value = "imgUrl", required = false) String imgUrl) {
        return sweetWechatMaoDengService.addBuilderImg(userId, imgUrl);
    }

}
