package com.bio.bio_backend.global.dto;


import com.fasterxml.jackson.annotation.JsonInclude;

import com.bio.bio_backend.global.constants.ApiResponseCode;
import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@RequiredArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponseDto<T> {

    private static final boolean SUCCESS = true;
    private static final boolean FAIL = false;

    private boolean success;
    private int code;
    private String message;
    private String description;
    private T data;

    private ApiResponseDto(boolean success, int code, String message, String description, T data){
        this.success = success;
        this.code = code;
        this.message = message;
        this.description = description;
        this.data = data;
    }

    public static <T> ApiResponseDto<T> success(ApiResponseCode responseCode, T data) {
        return new ApiResponseDto<T>(SUCCESS, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data);
    }

    public static <T> ApiResponseDto<T> success(ApiResponseCode responseCode) {
        return new ApiResponseDto<T>(SUCCESS, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null);
    }

    public static <T> ApiResponseDto<T> fail(ApiResponseCode responseCode, T data) {
        return new ApiResponseDto<T>(FAIL, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data);
    }

    public static <T> ApiResponseDto<T> fail(ApiResponseCode responseCode) {
        return new ApiResponseDto<T>(FAIL, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null);
    }

}

