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

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

import java.util.HashMap;
import java.util.Map;

/**
 * Standard API response following RESTful conventions
 * Matches common REST API structure: code, message, data
 */
public class ApiResponse implements Parcelable {
    public static final Creator<ApiResponse> CREATOR = new Creator<>() {
        @Override
        public ApiResponse createFromParcel(Parcel in) {
            return new ApiResponse(in);
        }

        @Override
        public ApiResponse[] newArray(int size) {
            return new ApiResponse[size];
        }
    };
    public int code;                        // Status code (200 = success, 4xx = client error, 5xx = server error)
    public String message;                  // Human-readable message
    public String timestamp;                // ISO 8601 format: "2025-10-11T23:01:00.000Z"
    public Map<String, Object> data;        // Response data as key-value pairs

    public ApiResponse() {
        data = new HashMap<>();
    }

    protected ApiResponse(Parcel in) {
        code = in.readInt();
        message = in.readString();
        timestamp = in.readString();
        data = in.readHashMap(Object.class.getClassLoader());
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(code);
        dest.writeString(message);
        dest.writeString(timestamp);
        dest.writeMap(data);
    }

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