package cn.ey.biz.module.system.api.errorcode;

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO;
import cn.ey.biz.module.system.enums.ApiConstants;
import cn.ey.biz.module.system.api.errorcode.dto.ErrorCodeRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;

@FeignClient(name = ApiConstants.NAME)
@Api(tags = "RPC 服务 - 错误码")
public interface ErrorCodeApi {

    String PREFIX = ApiConstants.PREFIX + "/error-code";

    @PostMapping(PREFIX + "/auto-generate")
    @ApiOperation("自动创建错误码")
    R<Boolean> autoGenerateErrorCodes(@Valid @RequestBody List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs);

    @GetMapping(PREFIX + "/list")
    @ApiOperation(value = "增量获得错误码数组", notes = "如果 minUpdateTime 为空时，则获取所有错误码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applicationName", value = "应用名", example = "system-server", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "minUpdateTime", value = "最小更新时间", dataTypeClass = Date.class)
    })
    R<List<ErrorCodeRespDTO>> getErrorCodeList(@RequestParam(value = "applicationName") String applicationName,
                                               @RequestParam(value = "minUpdateTime", required = false) Date minUpdateTime);

}
