package com.tzy.controller.appuser;

import com.alibaba.fastjson2.JSON;
import com.tzy.common.config.handle.ApiVersion;
import com.tzy.common.dto.InDto;
import com.tzy.common.dto.OutDTO;
import com.tzy.sportcard.api.service.IAppShareConfigService;
import com.tzy.sportcard.group.domain.AppShareConfig;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static cn.com.sand.hmpay.util.JacksonUtil.jsonToBean;

@Api(value = "app用户分享相关")
@RestController
@RequestMapping("/api/{version}/share")
@Slf4j
public class AppUserShareController {
    @Autowired
    private IAppShareConfigService appShareConfigService;

    @ResponseBody
    @RequestMapping(value = "/info", method = RequestMethod.POST)
    @ApiVersion(1.0)
    public OutDTO waitShippingCount(@RequestBody InDto inDto) {
        Long refId = inDto.getIntegerParam("refId").longValue();
        String typeStr = inDto.getString("type");
        AppShareConfig config = appShareConfigService.selectAppShareConfigById(refId,typeStr);
        return OutDTO.ok().put("AppShareConfig", config);
    }

    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiVersion(1.0)
    public OutDTO refuseByMerchant(@RequestBody InDto inDto) {
        String appShareConfigStr = inDto.getString("AppShareConfig");
        AppShareConfig config = new  AppShareConfig();
        config.setId(inDto.getIntegerParam("id")==null?0:inDto.getIntegerParam("id").longValue());
        config.setRefId(inDto.getIntegerParam("refId").longValue());
        config.setType(inDto.getString("type"));
        config.setConfig(inDto.getString("config"));
        AppShareConfig configval = appShareConfigService.selectAppShareConfigById(config.getRefId(),config.getType());
        if(configval==null){
            config.setId(null);
            appShareConfigService.insertAppUserWinCard(config);
        }
        else{
            appShareConfigService.updateAppUserWinCard(config);
        }
        return OutDTO.ok();
    }

}
