package cloud.nstart.terravault.ordinis.restapi.error;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.time.OffsetDateTime;
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public record ApiErrorResponse(
    int status,
    String code,
    String message,
    List<FieldError> fieldErrors,
    String traceId,
    OffsetDateTime timestamp) {

  public record FieldError(String path, String code, String message) {}

  public static ApiErrorResponse of(int status, String code, String message, String traceId) {
    return new ApiErrorResponse(status, code, message, null, traceId, OffsetDateTime.now());
  }

  public static ApiErrorResponse withFieldErrors(
      int status, String code, String message, List<FieldError> errors, String traceId) {
    return new ApiErrorResponse(status, code, message, errors, traceId, OffsetDateTime.now());
  }
}
