package org.wcs.serve.controller.app;

import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.api.AddApiBaseInfoReq;
import org.wcs.model.dto.serve.api.QueryApiBaseInfoReq;
import org.wcs.model.dto.serve.api.UpdateApiBaseInfoReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.api.QueryApiBaseInfoVo;
import org.wcs.serve.service.intf.IApiService;

import java.util.List;

/**
 * API 控制器
 */
@RestController
@RequestMapping("/app/api")
@ResponseBody
@RequiredArgsConstructor
public class ApiController {

    private final IApiService apiService;

    /**
     * 查询API基础信息
     * @param queryApiBaseInfoReq 查询API基础信息请求参数
     * @return API基础信息
     */
    @PostMapping("/queryApiBaseInfo")
    public AppServeDataResponse<List<QueryApiBaseInfoVo>> queryApiBaseInfo(@RequestBody QueryApiBaseInfoReq queryApiBaseInfoReq) {
        return apiService.queryApiBaseInfo(queryApiBaseInfoReq);
    }

    /**
     * 重新加载API基础信息
     * @return 重新加载结果
     */
    @PutMapping("/reloadApiKey")
    public AppServeResponse reloadApiKey() {
        return apiService.reloadApiKey();
    }

    /**
     * 添加API基础信息
     * @param addApiBaseInfoReq 添加API基础信息请求参数
     * @return 添加结果
     */
    @PostMapping("/addApiBaseInfo")
    public AppServeResponse addApiBaseInfo(@RequestBody @Validated AddApiBaseInfoReq addApiBaseInfoReq) {
        return apiService.addApiBaseInfo(addApiBaseInfoReq);
    }

    /**
     * 删除API基础信息
     * @param apiKey API键
     * @return 删除结果
     */
    @DeleteMapping("/deleteApiBaseInfo/{apiKey}")
    public AppServeResponse deleteApiBaseInfo(@PathVariable @NotBlank(message = "api键不能为空") String apiKey) {
        return apiService.deleteApiBaseInfo(apiKey);
    }

    /**
     * 更新API基础信息
     * @param updateApiBaseInfoReq 更新API基础信息请求参数
     * @return 更新结果
     */
    @PostMapping("/updateApiBaseInfo")
    public AppServeResponse updateApiBaseInfo(@RequestBody @Validated UpdateApiBaseInfoReq updateApiBaseInfoReq) {
        return apiService.updateApiBaseInfo(updateApiBaseInfoReq);
    }




}
