package com.amazon.ads.ema.api.model;

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

/**
 * Screenshot image chunk for streaming transfer when image exceeds Binder limit.
 */
public class ScreenshotChunk implements Parcelable {
    public int code;
    public String message;
    public String timestamp;

    public byte[] data;
    public long offset;
    public int chunkSize;
    public long totalSize;
    public boolean isLastChunk;

    public ScreenshotChunk() {
    }

    protected ScreenshotChunk(Parcel in) {
        code = in.readInt();
        message = in.readString();
        timestamp = in.readString();
        data = in.createByteArray();
        offset = in.readLong();
        chunkSize = in.readInt();
        totalSize = in.readLong();
        isLastChunk = in.readByte() != 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(code);
        dest.writeString(message);
        dest.writeString(timestamp);
        dest.writeByteArray(data);
        dest.writeLong(offset);
        dest.writeInt(chunkSize);
        dest.writeLong(totalSize);
        dest.writeByte((byte) (isLastChunk ? 1 : 0));
    }

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

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

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