package com.bernard.mcqinator.api.fragen;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Arrays;

/**
 * @author samy
 * @date on 04/05/17.
 */

public class BlocFrage extends Frage{
    private final String frage;
    private final String richtigAntwort;
    private final String[] falshAntworte;

    public BlocFrage(String frage, String richtigAntwort, String[] falshAntworte) {
        this.frage = frage;
        this.richtigAntwort = richtigAntwort;
        this.falshAntworte = falshAntworte;
    }

    public String getFrage() {
        return frage;
    }

    public String getRichtigAntwort() {
        return richtigAntwort;
    }

    public String[] getFalshAntworte() {
        return falshAntworte;
    }

    public static Parcelable.Creator<BlocFrage> CREATOR =  new Parcelable.Creator<BlocFrage>() {
        @Override
        public BlocFrage createFromParcel(Parcel source) {
            String frage = source.readString();
            String richtigAntwort = source.readString();
            String[] falshAntworte = new String[source.readInt()];
            source.readStringArray(falshAntworte);
            return new BlocFrage(frage,richtigAntwort,falshAntworte);
        }

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

    };

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(frage);
        dest.writeString(richtigAntwort);
        dest.writeInt(falshAntworte.length);
        dest.writeStringArray(falshAntworte);
    }

    @Override
    public Class<? extends Frage.Reply> getReplyClass() {
        return Reply.class;
    }

    @Override
    public String toString() {
        return "BlocFrage{" +
                "frage='" + frage + '\'' +
                ", richtigAntwort='" + richtigAntwort + '\'' +
                ", falshAntworte=" + Arrays.toString(falshAntworte) +
                "} " + super.toString();
    }

    public static class Reply extends Frage.Reply{
        final String answered;

        public Reply(String answered) {
            this.answered = answered;
        }

        public String getAnswered() {
            return answered;
        }

        public static Parcelable.Creator<BlocFrage.Reply> CREATOR = new BlocFrage.Creator<BlocFrage.Reply>() {
            public BlocFrage.Reply createFromParcel(Parcel source) {
                return new BlocFrage.Reply(source.readString());
            }

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


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

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

    }
}
