package im.actor.model.api.base;
/*
 *  Generated by the Actor API Scheme generator.  DO NOT EDIT!
 */

import im.actor.model.droidkit.bser.Bser;
import im.actor.model.droidkit.bser.BserValues;
import im.actor.model.droidkit.bser.BserWriter;

import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;

import static im.actor.model.droidkit.bser.Utils.*;
import java.io.IOException;
import im.actor.model.network.parser.*;

public class WeakUpdate extends RpcScope {

    public static final int HEADER = 0x1a;
    public static WeakUpdate fromBytes(byte[] data) throws IOException {
        return Bser.parse(new WeakUpdate(), data);
    }

    private long date;
    private int updateHeader;
    private byte[] update;

    public WeakUpdate(long date, int updateHeader, @NotNull byte[] update) {
        this.date = date;
        this.updateHeader = updateHeader;
        this.update = update;
    }

    public WeakUpdate() {

    }

    public long getDate() {
        return this.date;
    }

    public int getUpdateHeader() {
        return this.updateHeader;
    }

    @NotNull
    public byte[] getUpdate() {
        return this.update;
    }

    @Override
    public void parse(BserValues values) throws IOException {
        this.date = values.getLong(1);
        this.updateHeader = values.getInt(2);
        this.update = values.getBytes(3);
    }

    @Override
    public void serialize(BserWriter writer) throws IOException {
        writer.writeLong(1, this.date);
        writer.writeInt(2, this.updateHeader);
        if (this.update == null) {
            throw new IOException();
        }
        writer.writeBytes(3, this.update);
    }

    @Override
    public String toString() {
        String res = "update box WeakUpdate{";
        res += "date=" + this.date;
        res += ", updateHeader=" + this.updateHeader;
        res += ", update=" + byteArrayToStringCompact(this.update);
        res += "}";
        return res;
    }

    @Override
    public int getHeaderKey() {
        return HEADER;
    }
}
