package com.brframework.commoncms.web;

import com.brframework.commoncms.utils.SelectorManager;
import com.brframework.commonweb.json.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 揭光智
 * @date 2019/02/21
 */
@RestController
@Api(tags = "获取cms配置")
@RequestMapping("/admin/access/")
@Slf4j
public class AdminSelectorController {

    @Autowired
    private SelectorManager configManager;

    @ApiOperation(value = "获取select配置", notes = "获取select配置", produces = "text/plain")
    @GetMapping("v1/selector/select/{optionsMappingContext}/{key}")
    public JSONResult getSelectConfigByKey(@PathVariable String optionsMappingContext, @PathVariable String key) {
        return JSONResult.ok(configManager.getTotalSelects().get(optionsMappingContext).get(key));
    }

    @ApiOperation(value = "获取treeview配置", notes = "获取treeview配置", produces = "text/plain")
    @GetMapping("v1/selector/tree-view/{optionsMappingContext}")
    public JSONResult getTreeViewConfigByKey(@PathVariable String optionsMappingContext) {
        return JSONResult.ok(configManager.getTotalTreeViews().get(optionsMappingContext));
    }
}
