package com.tashow.cloud.infraapi.api.logger;

import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.infraapi.api.logger.dto.ApiErrorLogCreateReqDTO;
import com.tashow.cloud.infraapi.enums.ApiConstants;
import jakarta.validation.Valid;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
/** RPC 服务 - API 异常日志 */
public interface ApiErrorLogApi {

  String PREFIX = ApiConstants.PREFIX + "/api-error-log";

  @PostMapping(PREFIX + "/create")
  /** 创建 API 异常日志 */
  CommonResult<Boolean> createApiErrorLog(@Valid @RequestBody ApiErrorLogCreateReqDTO createDTO);

  /**
   * 【异步】创建 API 异常日志
   *
   * @param createDTO 异常日志 DTO
   */
  @Async
  default void createApiErrorLogAsync(ApiErrorLogCreateReqDTO createDTO) {
    createApiErrorLog(createDTO).checkError();
  }
}
