/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */
package org.elasticsearch.xpack.watcher.transport.actions.get;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.xpack.watcher.watch.Watch;

import java.io.IOException;

/**
 * The request to get the watch by name (id)
 */
public class GetWatchRequest extends MasterNodeReadRequest<GetWatchRequest> {

    private String id;

    public GetWatchRequest() {
    }

    /**
     * @param id name (id) of the watch to retrieve
     */
    public GetWatchRequest(String id) {
        this.id = id;
    }

    GetWatchRequest setId(String id) {
        this.id = id;
        return this;
    }

    @Override
    public ActionRequestValidationException validate() {
        ActionRequestValidationException validationException = null;
        if (id == null) {
            validationException = ValidateActions.addValidationError("watch id is missing", validationException);
        } else if (Watch.isValidId(id) == false) {
            validationException = ValidateActions.addValidationError("watch id contains whitespace", validationException);
        }

        return validationException;
    }


    /**
     * @return The name of the watch to retrieve
     */
    public String getId() {
        return id;
    }

    @Override
    public void readFrom(StreamInput in) throws IOException {
        super.readFrom(in);
        if (in.getVersion().before(Version.V_6_0_0_alpha1)) {
            in.readLong();
            in.readByte();
        }
        id = in.readString();
    }

    @Override
    public void writeTo(StreamOutput out) throws IOException {
        super.writeTo(out);
        if (out.getVersion().before(Version.V_6_0_0_alpha1)) {
            out.writeLong(1);
            out.writeByte(VersionType.INTERNAL.getValue());
        }
        out.writeString(id);
    }

    @Override
    public String toString() {
        return "get [" + id +"]";
    }
}

@@ -303,42 +303,8 @@
 t;%0A%0A
-import org.elasticsearch.Version;%0A
 impo
@@ -599,52 +599,8 @@
 ut;%0A
-import org.elasticsearch.index.VersionType;%0A
 impo
@@ -1833,134 +1833,8 @@
 n);%0A
-        if (in.getVersion().before(Version.V_6_0_0_alpha1)) %7B%0A            in.readLong();%0A            in.readByte();%0A        %7D%0A
     
@@ -1975,171 +1975,8 @@
 t);%0A
-        if (out.getVersion().before(Version.V_6_0_0_alpha1)) %7B%0A            out.writeLong(1);%0A            out.writeByte(VersionType.INTERNAL.getValue());%0A        %7D%0A
     

Remove stream serialization version checks, happen in 5.x (elastic/x-pack-elasticsearch#2002)