/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.recordservice;

import com.facebook.presto.spi.ConnectorSplit;
import com.facebook.presto.spi.HostAddress;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import java.util.List;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

public class RecordServiceSplit implements ConnectorSplit
{
  private final String connectorId;
  private final byte[] task;
  private final long taskSize;
  private final long hi;
  private final long lo;
  private final boolean resultOrdered;
  private final List<HostAddress> localHosts;

  @JsonCreator
  public RecordServiceSplit(
      @JsonProperty("connectorId") String connectorId,
      @JsonProperty("task") byte[] task,
      @JsonProperty("taskSize") long taskSize,
      @JsonProperty("hi") long hi,
      @JsonProperty("lo") long lo,
      @JsonProperty("resultOrdered") boolean resultOrdered,
      @JsonProperty("hosts") List<HostAddress> hosts)
  {

    this.connectorId = requireNonNull(connectorId, "connectorId is null");
    this.task = requireNonNull(task, "task is null");
    this.taskSize = requireNonNull(taskSize, "taskSize is null");
    this.hi = hi;
    this.lo = lo;
    this.resultOrdered = resultOrdered;
    this.localHosts = ImmutableList.copyOf(requireNonNull(hosts, "host is null"));
  }

  @Override
  public boolean isRemotelyAccessible()
  {
    return true;
  }

  @JsonProperty
  @Override
  public List<HostAddress> getAddresses()
  {
    return localHosts;
  }

  @Override
  public Object getInfo()
  {
    return ImmutableMap.builder()
        .put("task", task)
        .put("taskSize", taskSize)
        .put("hi", hi)
        .put("lo", lo)
        .put("resultOrdered", resultOrdered)
        .put("localHosts", localHosts)
        .build();
  }

  @Override
  public String toString()
  {
    return toStringHelper(this)
        .addValue(task)
        .addValue(taskSize)
        .addValue(hi)
        .addValue(lo)
        .toString();
  }

  @JsonProperty
  public String getConnectorId()
  {
    return connectorId;
  }

  @JsonProperty
  public byte[] getTask()
  {
    return task;
  }

  @JsonProperty
  public long getTaskSize()
  {
    return taskSize;
  }

  @JsonProperty
  public long getHi()
  {
    return hi;
  }

  @JsonProperty
  public long getLo()
  {
    return lo;
  }

  @JsonProperty
  public boolean getResultOrdered()
  {
    return resultOrdered;
  }
}

@@ -1310,25 +1310,24 @@
 ddress%3E 
-localHost
+addresse
 s;%0A%0A  @J
@@ -1660,20 +1660,24 @@
 operty(%22
-host
+addresse
 s%22) List
@@ -1694,20 +1694,23 @@
 ss%3E 
-host
+addresse
 s)%0A  %7B%0A
-%0A
     
@@ -1985,25 +1985,24 @@
    this.
-localHost
+addresse
 s = Immu
@@ -2037,20 +2037,29 @@
 ull(
-hosts, %22host
+addresses, %22addresses
  is 
@@ -2235,25 +2235,24 @@
  return 
-localHost
+addresse
 s;%0A  %7D%0A%0A
@@ -2498,30 +2498,28 @@
 ut(%22
-localHosts%22, localHost
+addresses%22, addresse
 s)%0A 

Fix JsonProperty issue