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

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

/**
 * Screen recording video chunk for streaming transfer
 */
public class ScreenRecordChunk implements Parcelable {
    public static final Creator<ScreenRecordChunk> CREATOR = new Creator<ScreenRecordChunk>() {
        @Override
        public ScreenRecordChunk createFromParcel(Parcel in) {
            return new ScreenRecordChunk(in);
        }

        @Override
        public ScreenRecordChunk[] newArray(int size) {
            return new ScreenRecordChunk[size];
        }
    };
    public int code;                    // Status code
    public String message;              // Status message
    public String timestamp;            // ISO 8601 timestamp
    public byte[] data;                 // Chunk data (up to 512KB)
    public long offset;                 // Offset in file
    public int chunkSize;               // Size of this chunk
    public long totalSize;              // Total file size
    public boolean isLastChunk;         // True if this is the last chunk

    public ScreenRecordChunk() {
    }

    protected ScreenRecordChunk(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;
    }
}
