package com.yaoai.admin.modelconfig;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.yaoai.admin.audit.annotation.AdminAudited;
import com.yaoai.admin.auth.StpAdminUtil;
import com.yaoai.ai.providers.config.PlatformModelConfigService;
import com.yaoai.ai.providers.config.PlatformModelSettings;
import com.yaoai.common.result.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@SaCheckLogin(type = "admin")
public class ModelConfigAdminController {

    private final PlatformModelConfigService platformModelConfigService;

    @GetMapping("/admin-api/model-config")
    @SaCheckRole(type = "admin", value = {"SUPER_ADMIN", "OPERATOR"}, mode = SaMode.OR)
    public Result<PlatformModelSettings> getConfig() {
        return Result.ok(platformModelConfigService.getAdminSettings());
    }

    @PutMapping("/admin-api/model-config")
    @AdminAudited(action = "MODEL_CONFIG_UPDATE", resource = "MODEL_CONFIG")
    @SaCheckRole(type = "admin", value = {"SUPER_ADMIN"})
    public Result<PlatformModelSettings> saveConfig(@RequestBody PlatformModelSettings settings) {
        return Result.ok(platformModelConfigService.saveAdminSettings(settings, StpAdminUtil.getLoginIdAsLong()));
    }
}
