package com.google.moviestvsentiments.service.web;

/**
 * A container for a value, its loading status and an error message.
 * @param <T> The type of value stored.
 */
public class Resource<T> {

    /**
     * Represents the loading status of a Resource.
     */
    public enum Status {
        LOADING,
        SUCCESS,
        ERROR
    }

    /**
     * Creates a new Resource with the provided value and a status of LOADING.
     * @param value The value to store in the Resource.
     * @param <T> The type of the value.
     * @return A new Resource with the provided value and a status of LOADING.
     */
    public static <T> Resource<T> loading(T value) {
        return new Resource<>(Status.LOADING, value, null);
    }

    /**
     * Creates a new Resource with the provided value and a status of SUCCESS.
     * @param value The value to store in the Resource.
     * @param <T> The type of the value.
     * @return A new Resource with the provided value and a status of SUCCESS.
     */
    public static <T> Resource<T> success(T value) {
        return new Resource<>(Status.SUCCESS, value, null);
    }

    /**
     * Creates a new Resource with the provided value, error message and a status of ERROR.
     * @param value The value to store in the Resource.
     * @param error The error message to store in the Resource.
     * @param <T> The type of the value.
     * @return A new Resource with the provided value, error message and a status of ERROR.
     */
    public static <T> Resource<T> error(T value, String error) {
        return new Resource<>(Status.ERROR, value, error);
    }

    private final Status status;
    private final T value;
    private final String error;

    private Resource(Status status, T value, String error) {
        this.status = status;
        this.value = value;
        this.error = error;
    }

    /**
     * Returns the loading status of the Resource.
     */
    public Status getStatus() {
        return status;
    }

    /**
     * Returns the value of the Resource.
     */
    public T getValue() {
        return value;
    }

    /**
     * Returns the error message of the Resource.
     */
    public String getError() {
        return error;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Resource<?> resource = (Resource<?>) o;

        if (status != resource.status) return false;
        if (value != null ? !value.equals(resource.value) : resource.value != null) return false;
        return error != null ? error.equals(resource.error) : resource.error == null;
    }

    @Override
    public int hashCode() {
        int result = status.hashCode();
        result = 31 * result + (value != null ? value.hashCode() : 0);
        result = 31 * result + (error != null ? error.hashCode() : 0);
        return result;
    }
}

@@ -45,16 +45,91 @@
 e.web;%0A%0A
+import com.google.auto.value.AutoValue;%0Aimport javax.annotation.Nullable;%0A%0A
 /**%0A * A
@@ -237,22 +237,42 @@
 ed.%0A */%0A
-public
+@AutoValue%0Apublic abstract
  class R
@@ -768,32 +768,42 @@
      return new 
+AutoValue_
 Resource%3C%3E(Statu
@@ -1169,32 +1169,42 @@
      return new 
+AutoValue_
 Resource%3C%3E(Statu
@@ -1676,24 +1676,34 @@
  return new 
+AutoValue_
 Resource%3C%3E(S
@@ -1741,255 +1741,8 @@
  %7D%0A%0A
-    private final Status status;%0A    private final T value;%0A    private final String error;%0A%0A    private Resource(Status status, T value, String error) %7B%0A        this.status = status;%0A        this.value = value;%0A        this.error = error;%0A    %7D%0A%0A
     
@@ -1815,16 +1815,25 @@
  public 
+abstract 
 Status g
@@ -1846,39 +1846,9 @@
 us()
- %7B%0A        return status;%0A    %7D
+;
 %0A%0A  
@@ -1911,57 +1911,51 @@
     
-public T getValue() %7B%0A        return value;%0A    %7D
+@Nullable%0A    public abstract T getValue();
 %0A%0A  
@@ -2026,764 +2026,55 @@
     
-public String getError() %7B%0A        return error;%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (o == null %7C%7C getClass() != o.getClass()) return false;%0A%0A        Resource%3C?%3E resource = (Resource%3C?%3E) o;%0A%0A        if (status != resource.status) return false;%0A        if (value != null ? !value.equals(resource.value) : resource.value != null) return false;%0A        return error != null ? error.equals(resource.error) : resource.error == null;%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = status.hashCode();%0A        result = 31 * result + (value != null ? value.hashCode() : 0);%0A        result = 31 * result + (error != null ? error.hashCode() : 0);%0A        return result;%0A    %7D
+@Nullable%0A    public abstract String getError();
 %0A%7D%0A

Convert Resource to AutoValue class