/*
 * Copyright (c) 2017 "JackWhite20"
 *
 * This file is part of Sycorax.
 *
 * Sycorax is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.jackwhite20.sycorax.shared.protocol.packet.packets;

import de.jackwhite20.cascade.shared.protocol.io.PacketReader;
import de.jackwhite20.cascade.shared.protocol.io.PacketWriter;
import de.jackwhite20.cascade.shared.protocol.packet.PacketInfo;
import de.jackwhite20.sycorax.shared.protocol.packet.SycoraxPacket;
import de.jackwhite20.sycorax.shared.serialize.Type;

/**
 * Created by JackWhite20 on 29.11.2015.
 */
@PacketInfo(id = 5)
public class SetExpirePacket extends SycoraxPacket {

    private Object key;

    private int secondsToLive;

    public SetExpirePacket() {

    }

    public SetExpirePacket(Object key, int secondsToLive) {

        this.key = key;
        this.secondsToLive = secondsToLive;
    }

    public Object key() {

        return key;
    }

    public int secondsToLive() {

        return secondsToLive;
    }

    @Override
    public void read(PacketReader reader) throws Exception {

        key = serializer().read(reader);
        secondsToLive = reader.readInt();
    }

    @Override
    public void write(PacketWriter writer) throws Exception {

        serializer().write(Type.type(key), key, writer);
        writer.writeInt(secondsToLive);
    }
}
