package com.cd.detection.config.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponseDto<T> {

  private final T data;
  private final Error error;

  private ApiResponseDto(T data, Error error) {
    this.data = data;
    this.error = error;
  }

  // 성공
  public static <T> ApiResponseDto<T> ok(T data) {
    return new ApiResponseDto<>(data, null);
  }

  // 실패
  public static <T> ApiResponseDto<T> fail(String code, String message) {
    return new ApiResponseDto<>(null, new Error(code, message));
  }

  @Getter
  public static class Error {
    private final String code;
    private final String message;

    public Error(String code, String message) {
      this.code = code;
      this.message = message;
    }
  }
}
