package com.sptg.gateway.controller.permissions;

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.security.annotation.Security;
import com.sptg.common.security.enums.DataFormatEnum;
import com.sptg.permissions.api.entity.Conf;
import com.sptg.permissions.api.feigns.ConfFeign;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/permissions/conf")
@RequiredArgsConstructor
public class ConfController {

    private final ConfFeign confFeign;

    @Security(format = DataFormatEnum.JSON)
    @GetMapping(value = "/getEntityByToken")
    public ResultBean<String> setup(@RequestParam(value = "token", required = true) String token){
        Conf conf = confFeign.getEntityByToken(token);
        if(conf == null){
            return new ResultBean<>(ResultEnum.FAILURE, "参数配置不存在");
        }
        return new ResultBean<>(ResultEnum.SUCCESS, conf.getConfValue());
    }
}
