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

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

/**
 * Screenshot data containing image information
 */
public class ScreenshotData implements Parcelable {
    public static final Creator<ScreenshotData> CREATOR = new Creator<>() {
        @Override
        public ScreenshotData createFromParcel(Parcel in) {
            return new ScreenshotData(in);
        }

        @Override
        public ScreenshotData[] newArray(int size) {
            return new ScreenshotData[size];
        }
    };
    public byte[] imageData;            // Raw image bytes (null if chunked)
    public String format;               // "PNG", "JPEG", or "WEBP"
    public int widthPx;                 // Image width in pixels
    public int heightPx;                // Image height in pixels
    public long fileSizeBytes;          // Image size in bytes
    public boolean chunked;             // True if image exceeds Binder limit
    public long totalSize;              // Total image size in bytes (set when chunked=true)

    public ScreenshotData() {
    }

    protected ScreenshotData(Parcel in) {
        imageData = in.createByteArray();
        format = in.readString();
        widthPx = in.readInt();
        heightPx = in.readInt();
        fileSizeBytes = in.readLong();
        chunked = in.readByte() != 0;
        totalSize = in.readLong();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByteArray(imageData);
        dest.writeString(format);
        dest.writeInt(widthPx);
        dest.writeInt(heightPx);
        dest.writeLong(fileSizeBytes);
        dest.writeByte((byte) (chunked ? 1 : 0));
        dest.writeLong(totalSize);
    }

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