package com.hclsoftware.sso.kerberos.v2.response;

import com.hclsoftware.sso.kerberos.constants.Constants;
import com.hclsoftware.sso.kerberos.constants.CustomResponseStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.springframework.http.HttpStatus;

import static com.hclsoftware.sso.kerberos.constants.CustomResponseStatus.*;

@Data
@Builder
@AllArgsConstructor
public class GenericResponse<T> {
    private String message;
    private T data;
    private CustomResponseStatus status;
    private HttpStatus statusCode;

    public static <T> GenericResponse<T> empty() {
        return success(null);
    }

    public static <T> GenericResponse<T> success(T data) {
        return GenericResponse.<T>builder()
                .statusCode(HttpStatus.OK)
                .status(SUCCESS)
                .data(data)
                .build();
    }

    public static <T> GenericResponse<T> success(T data, String message) {
        return GenericResponse.<T>builder()
                .statusCode(HttpStatus.OK)
                .status(SUCCESS)
                .data(data)
                .build();
    }

    public static <T> GenericResponse<T> error() {
        return GenericResponse.<T>builder()
                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR)
                .status(ERROR)
                .build();
    }
    public static <T> GenericResponse<T> error(CustomResponseStatus status, HttpStatus httpStatus) {
        return GenericResponse.<T>builder()
                .statusCode(httpStatus)
                .status(status)
                .build();
    }
    public static <T> GenericResponse<T> error(CustomResponseStatus status, HttpStatus httpStatus, T data) {
        return GenericResponse.<T>builder()
                .statusCode(httpStatus)
                .status(status)
                .data(data)
                .build();
    }
}
