/*
* Copyright 2017 WalmartLabs
* 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.
*/

package com.ClassDojoReactNativeApi.ern.model;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.List;

import com.walmartlabs.electrode.reactnative.bridge.Bridgeable;

import static com.walmartlabs.electrode.reactnative.bridge.util.BridgeArguments.*;

public class LogEvent implements Parcelable, Bridgeable {

    private String eventIdentifier;
    private String actionIdentifier;
    private String eventValue;

    private LogEvent() {}

    private LogEvent(Builder builder) {
        this.eventIdentifier = builder.eventIdentifier;
        this.actionIdentifier = builder.actionIdentifier;
        this.eventValue = builder.eventValue;
    }

    private LogEvent(Parcel in) {
        this(in.readBundle());
    }

    public LogEvent(@NonNull Bundle bundle) {
        this.eventIdentifier = bundle.getString("eventIdentifier");
        this.actionIdentifier = bundle.getString("actionIdentifier");
        this.eventValue = bundle.getString("eventValue");
    }

    public static final Creator<LogEvent> CREATOR = new Creator<LogEvent>() {
        @Override
        public LogEvent createFromParcel(Parcel in) {
            return new LogEvent(in);
        }

        @Override
        public LogEvent[] newArray(int size) {
            return new LogEvent[size];
        }
    };

    /**
    * Event Identifier
    *
    * @return String
    */
    @Nullable
    public String getEventIdentifier() {
        return eventIdentifier;
    }

    /**
    * Action Identifier
    *
    * @return String
    */
    @Nullable
    public String getActionIdentifier() {
        return actionIdentifier;
    }

    /**
    * Event Value
    *
    * @return String
    */
    @Nullable
    public String getEventValue() {
        return eventValue;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeBundle(toBundle());
    }

    @NonNull
    @Override
    public Bundle toBundle() {
        Bundle bundle = new Bundle();
        if(eventIdentifier != null) {
            bundle.putString("eventIdentifier", this.eventIdentifier );
        }
        if(actionIdentifier != null) {
            bundle.putString("actionIdentifier", this.actionIdentifier );
        }
        if(eventValue != null) {
            bundle.putString("eventValue", this.eventValue );
        }
        return bundle;
    }

    @Override
    public String toString() {
        return "{"
        + "eventIdentifier:" + (eventIdentifier != null ? "\"" + eventIdentifier + "\"" : null)+ ","
        + "actionIdentifier:" + (actionIdentifier != null ? "\"" + actionIdentifier + "\"" : null)+ ","
        + "eventValue:" + (eventValue != null ? "\"" + eventValue + "\"" : null)
        + "}";
    }

    public static class Builder {
        private String eventIdentifier;
        private String actionIdentifier;
        private String eventValue;

        public Builder() {
        }

        @NonNull
        public Builder eventIdentifier(@Nullable String eventIdentifier) {
            this.eventIdentifier = eventIdentifier;
            return this;
        }
        @NonNull
        public Builder actionIdentifier(@Nullable String actionIdentifier) {
            this.actionIdentifier = actionIdentifier;
            return this;
        }
        @NonNull
        public Builder eventValue(@Nullable String eventValue) {
            this.eventValue = eventValue;
            return this;
        }

        @NonNull
        public LogEvent build() {
            return new LogEvent(this);
        }
    }
}
