package com.zhongshu.card.server.core.controller.openAPI;

import com.github.microservice.auth.client.constant.AuthConstant;
import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.server.core.service.openAPI.OpenApiConfigManagerService;
import com.zhongshu.card.server.core.service.openAPI.OpenAppManagerService;
import com.zhongshu.opengateway.client.model.OpenApiConfigModel;
import com.zhongshu.opengateway.client.model.SignModel;
import com.zhongshu.opengateway.client.model.param.AddApiParam;
import com.zhongshu.opengateway.client.model.param.LimitParam;
import com.zhongshu.opengateway.client.model.param.OpenApiSearchParam;
import com.zhongshu.opengateway.client.model.ret.ResultContent;
import com.zhongshu.opengateway.client.service.OpenApiConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/openApi/apiConfig")
@Tag(name = "OpenApi--接口管理")
public class OpenApiConfigManagerController {

    @Autowired
    OpenApiConfigManagerService openApiConfigManagerService;

//    /** 自定义条件分页查询所有openApi列表 */
//    @Operation(summary = "分页查询所有openApi列表", description = "分页查询所有openApi列表")
////    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
////    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.Project, remark = "")
//    @RequestMapping(value = "page", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
//    public ResultContent pageByMql(String appId,
//                                   @PageableDefault(sort = "createTime", direction = Sort.Direction.DESC) Pageable pageable){
//        return openApiConfigManagerService.pageAll(appId, pageable);
//    }

//    @Operation(summary = "添加接口", description = "添加接口")
////    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
////    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
//    @RequestMapping(value = "quoteOpenApi", method = RequestMethod.POST)
//    public ResultContent quoteOpenApi(@RequestBody AddApiParam param){
//        return openApiConfigManagerService.quoteOpenApi(param);
//    }


    @Operation(summary = "分页查询App下openApi", description = "分页查询App下openApi")
//    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
//    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
    @RequestMapping(value = "pageByApp", method = RequestMethod.POST)
    public ResultContent pageByApp(Pageable pageable, OpenApiSearchParam param){
        param.setPage(param.getPage());
        param.setSize(param.getSize());
        return openApiConfigManagerService.pageByApp(param);
    }
//    @Operation(summary = "分页查询App添加列表", description = "分页查询App下openApi")
////    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
////    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
//    @RequestMapping(value = "pageAddList", method = RequestMethod.POST)
//    public ResultContent pageAddList(@RequestBody OpenApiSearchParam param){
//        return openApiConfigManagerService.pageAddList(param);
//    }

//    @Operation(summary = "禁用/启用", description = "禁用/启用")
////    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
////    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
//    @RequestMapping(value = "disable", method = RequestMethod.GET)
//    public ResultContent disable(@Parameter(name = "id", description = "接口id") @RequestParam(value = "id") String id){
//        return openApiConfigManagerService.disable(id);
//    }
//
//    @Operation(summary = "删除", description = "删除")
////    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
////    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
//    @RequestMapping(value = "delete", method = RequestMethod.GET)
//    public ResultContent delete(@Parameter(name = "id", description = "接口id") @RequestParam(name = "id") String id){
//        return openApiConfigManagerService.delete(id);
//    }
//
//    @Operation(summary = " 获取openApi详情", description = " 获取openApi详情")
////    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
////    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
//    @RequestMapping(value = "get", method = RequestMethod.GET)
//    public ResultContent get(@Parameter(name = "id", description = "接口id") @RequestParam(name = "id") String id){
//        return openApiConfigManagerService.get(id);
//    }
//
//    @Operation(summary = "设置限流规则", description = "设置限流规则")
////    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
////    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
//    @RequestMapping(value = "setLimit", method = RequestMethod.POST)
//    public ResultContent setLimit(@RequestBody LimitParam limitParam){
//        return openApiConfigManagerService.setLimit(limitParam);
//    }
}
