package com.ga.common.system;

import com.ga.common.annotation.RequirePermission;
import com.ga.common.model.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "시스템설정")
@RestController
@RequestMapping("/api/system/config")
@RequiredArgsConstructor
public class SystemConfigController {

    private final SystemConfigService service;

    @GetMapping
    @RequirePermission(menu = "SYSTEM_CONFIG", perm = "READ")
    public ApiResponse<List<SystemConfigVO>> list(@RequestParam(required = false) String group) {
        return ApiResponse.ok(group == null || group.isBlank() ? service.listAll() : service.listByGroup(group));
    }

    @PutMapping("/{configKey}")
    @RequirePermission(menu = "SYSTEM_CONFIG", perm = "UPDATE")
    public ApiResponse<Void> update(@PathVariable String configKey, @RequestBody SystemConfigVO vo) {
        vo.setConfigKey(configKey);
        service.update(vo);
        return ApiResponse.ok();
    }
}
