package com.jscape.inet.sftp.protocol.v3.messages;

import com.jscape.inet.sftp.protocol.messages.Message;
import com.jscape.util.net.connection.MessageConnection;

import java.util.Arrays;

import static com.jscape.util.Parameters.assertNotNull;

/**
 * @author Alex Usun
 */
public class SshFxpRead
        extends Message<SshFxpRead.Handler> {

    public final int id;
    public final byte[] handle;
    public final long offset;
    public final int length;

    public SshFxpRead(int id, byte[] handle, long offset, int length) {
        this.id = id;

        assertNotNull(handle);
        this.handle = handle;

        this.offset = offset;
        this.length = length;
    }

    @Override
    public void accept(Handler handler, MessageConnection<Message> connection) {
        handler.handle(this, connection);
    }

    @Override
    public String toString() {
        return "SshFxpRead {"
                + "id=" + this.id
                + ", handle=" + Arrays.toString(this.handle)
                + ", offset=" + this.offset
                + ", length=" + this.length
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

        void handle(SshFxpRead message, MessageConnection<Message> connection);

    }
}
