package com.zhongshu.card.server.core.controller.visitor;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.CodeParam;
import com.zhongshu.card.client.model.visitor.setting.VisitorSettingModel;
import com.zhongshu.card.client.model.visitor.setting.VisitorSettingParam;
import com.zhongshu.card.server.core.service.visitor.VisitorSettingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 组件访客配置
 *
 * @author TRX
 * @date 2024/7/26
 */
@RestController
@RequestMapping("/visitorSetting")
@Tag(name = "访客管理-配置参数")
public class VisitorSettingController {

    @Autowired
    private VisitorSettingService visitorSettingService;

    @Operation(summary = "得到配置（传入组件id）", description = "得到配置")
    @RequestMapping(value = "getInfo", method = {RequestMethod.POST})
    public ResultContent<VisitorSettingModel> getInfo(@RequestBody VisitorSettingParam param) {
        return visitorSettingService.getInfo(param.getSceneComponentId(), param.getProjectOid());
    }

    @Operation(summary = "得到配置（传入组件code）", description = "得到配置")
    @RequestMapping(value = "getInfoByCode", method = {RequestMethod.POST})
    public ResultContent<VisitorSettingModel> getInfoByCode(@RequestBody CodeParam param) {
        return visitorSettingService.getInfoByCode(param.getCode(), param.getProjectOid());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存配置", description = "保存配置")
    @RequestMapping(value = "saveInfo", method = {RequestMethod.POST})
    public ResultContent saveInfo(@RequestBody @Valid VisitorSettingParam param) {
        return visitorSettingService.saveInfo(param);
    }

}
