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 int code;
    private String message;
    private String description;
    private T data;

    private static final int SUCCESS = 200;

    private ApiResponseDto(int code, String message, String description, T data){
        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.name(), responseCode.getDescription(), data);
    }

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

}

