package com.yc.ship.module.marketing.controller.app.params;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.module.marketing.controller.app.params.vo.AppParamsSaveVo;
import com.yc.ship.module.marketing.service.params.MarketingParamsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.yc.ship.framework.common.pojo.CommonResult.success;


@Tag(name = "用户 APP - 全民分销-保存小程序参数")
@RestController
@RequestMapping("/marketing/params")
@Validated
public class AppMarketingParamsController {

    @Resource
    private MarketingParamsService marketingParamsService;

    @PostMapping("/create")
    @Operation(summary = "创建全民分销-小程序码参数")
    public CommonResult<Long> createParams(@Valid @RequestBody AppParamsSaveVo createReqVO) {
        return success(marketingParamsService.createParams(createReqVO));
    }


    @GetMapping("/get")
    @Operation(summary = "获得全民分销-分销员")
    public CommonResult<JSONObject> getParams(Long id) {
        String params = marketingParamsService.getParams(id);
        return success(JSONUtil.parseObj(params));
    }


}
