/*
 * 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.hive;

import io.airlift.event.client.EventField;
import io.airlift.event.client.EventType;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import java.util.Map;

import static java.util.Objects.requireNonNull;

@Immutable
@EventType("WriteCompletedEvent")
public class WriteCompletedEvent
{
    private final String queryId;
    private final String path;
    private final String schemaName;
    private final String tableName;
    private final String partitionName;
    private final String storageFormat;
    private final String writerImplementation;
    private final String prestoVersion;
    private final String serverAddress;
    private final String principal;
    private final String environment;
    private final Map<String, String> sessionProperties;
    private final Long bytes;
    private final long rows;

    public WriteCompletedEvent(
            String queryId,
            String path,
            String schemaName,
            String tableName,
            @Nullable String partitionName,
            String storageFormat,
            String writerImplementation,
            String prestoVersion,
            String serverAddress,
            @Nullable String principal,
            String environment,
            Map<String, String> sessionProperties,
            @Nullable Long bytes,
            long rows)
    {
        this.queryId = requireNonNull(queryId, "queryId is null");
        this.path = requireNonNull(path, "path is null");
        this.schemaName = requireNonNull(schemaName, "schemaName is null");
        this.tableName = requireNonNull(tableName, "tableName is null");
        this.partitionName = partitionName;
        this.storageFormat = requireNonNull(storageFormat, "storageFormat is null");
        this.writerImplementation = requireNonNull(writerImplementation, "writerImplementation is null");
        this.prestoVersion = requireNonNull(prestoVersion, "prestoVersion is null");
        this.serverAddress = requireNonNull(serverAddress, "serverAddress is null");
        this.principal = principal;
        this.environment = requireNonNull(environment, "environment is null");
        this.sessionProperties = requireNonNull(sessionProperties, "sessionProperties is null");
        this.bytes = bytes;
        this.rows = rows;
    }

    @EventField
    public String getQueryId()
    {
        return queryId;
    }

    @EventField
    public String getPath()
    {
        return path;
    }

    @EventField
    public String getSchemaName()
    {
        return schemaName;
    }

    @EventField
    public String getTableName()
    {
        return tableName;
    }

    @Nullable
    @EventField
    public String getPartitionName()
    {
        return partitionName;
    }

    @EventField
    public String getStorageFormat()
    {
        return storageFormat;
    }

    @EventField
    public String getWriterImplementation()
    {
        return writerImplementation;
    }

    @EventField
    public String getPrestoVersion()
    {
        return prestoVersion;
    }

    @EventField
    public String getServerAddress()
    {
        return serverAddress;
    }

    @Nullable
    @EventField
    public String getPrincipal()
    {
        return principal;
    }

    @EventField
    public String getEnvironment()
    {
        return environment;
    }

    @EventField
    public Map<String, String> getSessionProperties()
    {
        return sessionProperties;
    }

    @Nullable
    @EventField
    public Long getBytes()
    {
        return bytes;
    }

    @EventField
    public long getRows()
    {
        return rows;
    }
}

@@ -633,16 +633,77 @@
 tField;%0A
+import io.airlift.event.client.EventField.EventFieldMapping;%0A
 import i
@@ -814,24 +814,50 @@
 Immutable;%0A%0A
+import java.time.Instant;%0A
 import java.
@@ -1326,29 +1326,20 @@
  String 
-serverAddress
+host
 ;%0A    pr
@@ -1521,16 +1521,69 @@
 ng rows;
+%0A    private final Instant timestamp = Instant.now();
 %0A%0A    pu
@@ -2702,29 +2702,20 @@
    this.
-serverAddress
+host
  = requi
@@ -3797,32 +3797,71 @@
 %0A    @EventField
+(fieldMapping = EventFieldMapping.HOST)
 %0A    public Stri
@@ -3870,21 +3870,12 @@
  get
-ServerAddress
+Host
 ()%0A 
@@ -3894,29 +3894,20 @@
  return 
-serverAddress
+host
 ;%0A    %7D%0A
@@ -4384,11 +4384,144 @@
 s;%0A    %7D
+%0A%0A    @EventField(fieldMapping = EventFieldMapping.TIMESTAMP)%0A    public Instant getTimestamp()%0A    %7B%0A        return timestamp;%0A    %7D
 %0A%7D%0A

Add event time to write complete event