// Path: app/src/main/java/br/com/catbag/gifreduxsample/actions/PayloadParams.java
// public final class PayloadParams {
// 
//     public static final String PARAM_UUID = "PARAM_UUID";
//     public static final String PARAM_PATH = "PARAM_PATH";
//     public static final String PARAM_GIFS = "PARAM_GIFS";
//     public static final String PARAM_HAS_MORE = "PARAM_HAS_MORE";
// 
//     private PayloadParams() {
//     }
// }
// 
// Path: app/src/main/java/br/com/catbag/gifreduxsample/models/Gif.java
// @SuppressWarnings("PMD.BooleanGetMethodName")
// @Value.Immutable
// @JsonSerialize(as = ImmutableGif.class)
// @JsonDeserialize(as = ImmutableGif.class)
// public abstract class Gif {
// 
//     public enum Status {
//         PAUSED, LOOPING, DOWNLOADING, DOWNLOADED, NOT_DOWNLOADED, DOWNLOAD_FAILED
//     }
// 
//     //abstract method are immutable by default
//     public abstract String getUuid();
// 
//     @Value.Default
//     public String getPath() {
//         return "";
//     }
// 
//     public abstract String getUrl();
//     
//     public abstract String getTitle();
// 
//     @Value.Default
//     public boolean getWatched() {
//         return false;
//     }
// 
//     @Value.Default
//     public Status getStatus() {
//         return Status.NOT_DOWNLOADED;
//     }
// 
//     public String toJson() throws JsonProcessingException {
//         return new ObjectMapper().writeValueAsString(this);
//     }
// 
//     public static Gif fromJson(String json) throws IOException {
//         return new ObjectMapper().readValue(json, Gif.class);
//     }
// 
// }


import java.util.Map;
import br.com.catbag.gifreduxsample.actions.PayloadParams;
import br.com.catbag.gifreduxsample.models.Gif;
import br.com.catbag.gifreduxsample.models.ImmutableGif;
package br.com.catbag.gifreduxsample.reducers;



/**
 Copyright 26/10/2016
 Felipe Piñeiro (fpbitencourt@gmail.com),
 Nilton Vasques (nilton.vasques@gmail.com) and
 Raul Abreu (raulccabreu@gmail.com)

 Be free to ask for help, email us!

 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 in compliance with the License. You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software distributed under the License
 is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 implied. See the License for the specific language governing permissions and limitations under
 the License.
 **/

final class GifInnerReducer {
    private GifInnerReducer() {
    }

    public static Gif downloadStart(Gif gif) {
        if (gif.getStatus() != Gif.Status.NOT_DOWNLOADED) return gif;
        return createImmutableGifBuilder(gif)
                .status(Gif.Status.DOWNLOADING)
                .build();
    }

    public static Gif downloadSuccess(Gif gif, Map<String, Object> params) {
        if (gif.getStatus() != Gif.Status.DOWNLOADING) return gif;
        return createImmutableGifBuilder(gif)
                .status(Gif.Status.DOWNLOADED)
                .path((String) params.get(PayloadParams.PARAM_PATH))
                .build();
    }

    public static Gif downloadFailure(Gif gif) {
        if (gif.getStatus() != Gif.Status.DOWNLOADING) return gif;
        return createImmutableGifBuilder(gif)
                .status(Gif.Status.DOWNLOAD_FAILED)
                .build();
    }

// Path: app/src/main/java/br/com/catbag/gifreduxsample/actions/PayloadParams.java
// public final class PayloadParams {
// 
//     public static final String PARAM_UUID = "PARAM_UUID";
//     public static final String PARAM_PATH = "PARAM_PATH";
//     public static final String PARAM_GIFS = "PARAM_GIFS";
//     public static final String PARAM_HAS_MORE = "PARAM_HAS_MORE";
// 
//     private PayloadParams() {
//     }
// }
// 
// Path: app/src/main/java/br/com/catbag/gifreduxsample/models/Gif.java
// @SuppressWarnings("PMD.BooleanGetMethodName")
// @Value.Immutable
// @JsonSerialize(as = ImmutableGif.class)
// @JsonDeserialize(as = ImmutableGif.class)
// public abstract class Gif {
// 
//     public enum Status {
//         PAUSED, LOOPING, DOWNLOADING, DOWNLOADED, NOT_DOWNLOADED, DOWNLOAD_FAILED
//     }
// 
//     //abstract method are immutable by default
//     public abstract String getUuid();
// 
//     @Value.Default
//     public String getPath() {
//         return "";
//     }
// 
//     public abstract String getUrl();
//     
//     public abstract String getTitle();
// 
//     @Value.Default
//     public boolean getWatched() {
//         return false;
//     }
// 
//     @Value.Default
//     public Status getStatus() {
//         return Status.NOT_DOWNLOADED;
//     }
// 
//     public String toJson() throws JsonProcessingException {
//         return new ObjectMapper().writeValueAsString(this);
//     }
// 
//     public static Gif fromJson(String json) throws IOException {
//         return new ObjectMapper().readValue(json, Gif.class);
//     }
// 
// }


// Path: app/src/main/java/br/com/catbag/gifreduxsample/reducers/GifInnerReducer.java
import java.util.Map;
import br.com.catbag.gifreduxsample.actions.PayloadParams;
import br.com.catbag.gifreduxsample.models.Gif;
import br.com.catbag.gifreduxsample.models.ImmutableGif;

package br.com.catbag.gifreduxsample.reducers;



/**
 Copyright 26/10/2016
 Felipe Piñeiro (fpbitencourt@gmail.com),
 Nilton Vasques (nilton.vasques@gmail.com) and
 Raul Abreu (raulccabreu@gmail.com)

 Be free to ask for help, email us!

 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 in compliance with the License. You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software distributed under the License
 is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 implied. See the License for the specific language governing permissions and limitations under
 the License.
 **/

final class GifInnerReducer {
    private GifInnerReducer() {
    }

    public static Gif downloadStart(Gif gif) {
        if (gif.getStatus() != Gif.Status.NOT_DOWNLOADED) return gif;
        return createImmutableGifBuilder(gif)
                .status(Gif.Status.DOWNLOADING)
                .build();
    }

    public static Gif downloadSuccess(Gif gif, Map<String, Object> params) {
        if (gif.getStatus() != Gif.Status.DOWNLOADING) return gif;
        return createImmutableGifBuilder(gif)
                .status(Gif.Status.DOWNLOADED)
                .path((String) params.get(PayloadParams.PARAM_PATH))
                .build();
    }

    public static Gif downloadFailure(Gif gif) {
        if (gif.getStatus() != Gif.Status.DOWNLOADING) return gif;
        return createImmutableGifBuilder(gif)
                .status(Gif.Status.DOWNLOAD_FAILED)
                .build();
    }

    public static Gif play(Gif gif) {