package org.linlinjava.jz.admin.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.jz.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.jz.core.system.SystemConfig;
import org.linlinjava.jz.core.util.JacksonUtil;
import org.linlinjava.jz.core.util.ResponseUtil;
import org.linlinjava.jz.db.service.JzCallConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/config")
@Validated
public class AdminConfigController {
    private final Log logger = LogFactory.getLog(AdminConfigController.class);

    @Autowired
    private JzCallConfigService systemConfigService;


    @RequiresPermissions("admin:config:call:list")
    @RequiresPermissionsDesc(menu = {"电访中心", "外拨配置"}, button = "详情")
    @GetMapping("/call")
    public Object listWx() {
        Map<String, String> data = systemConfigService.listCall();
        return ResponseUtil.ok(data);

    }

    @RequiresPermissions("admin:config:call:updateConfigs")
    @RequiresPermissionsDesc(menu = {"电访中心", "外拨配置"}, button = "编辑")
    @PostMapping("/call")
    public Object updateWx(@RequestBody String body) {
        Map<String, String> data = JacksonUtil.toMap(body);
        systemConfigService.updateConfig(data);
        SystemConfig.updateConfigs(data);
        return ResponseUtil.ok();
    }
}
