/*
 * 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 io.trino.plugin.hive.metastore.file;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import io.trino.plugin.hive.metastore.Database;
import io.trino.spi.security.PrincipalType;

import java.util.Map;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

public class DatabaseMetadata
{
    private final Optional<String> writerVersion;
    private final Optional<String> ownerName;
    private final Optional<PrincipalType> ownerType;
    private final Optional<String> comment;
    private final Map<String, String> parameters;

    @JsonCreator
    public DatabaseMetadata(
            @JsonProperty("writerVersion") Optional<String> writerVersion,
            @JsonProperty("ownerName") Optional<String> ownerName,
            @JsonProperty("ownerType") Optional<PrincipalType> ownerType,
            @JsonProperty("comment") Optional<String> comment,
            @JsonProperty("parameters") Map<String, String> parameters)
    {
        this.writerVersion = requireNonNull(writerVersion, "writerVersion is null");
        this.ownerName = requireNonNull(ownerName, "ownerName is null");
        this.ownerType = requireNonNull(ownerType, "ownerType is null");
        this.comment = requireNonNull(comment, "comment is null");
        this.parameters = ImmutableMap.copyOf(requireNonNull(parameters, "parameters is null"));
    }

    public DatabaseMetadata(String currentVersion, Database database)
    {
        this.writerVersion = Optional.of(requireNonNull(currentVersion, "currentVersion is null"));
        this.ownerName = database.getOwnerName();
        this.ownerType = database.getOwnerType();
        this.comment = database.getComment();
        this.parameters = database.getParameters();
    }

    @JsonProperty
    public Optional<String> getWriterVersion()
    {
        return writerVersion;
    }

    @JsonProperty
    public Optional<String> getOwnerName()
    {
        return ownerName;
    }

    @JsonProperty
    public Optional<PrincipalType> getOwnerType()
    {
        return ownerType;
    }

    @JsonProperty
    public Optional<String> getComment()
    {
        return comment;
    }

    @JsonProperty
    public Map<String, String> getParameters()
    {
        return parameters;
    }

    public Database toDatabase(String databaseName, String location)
    {
        return Database.builder()
                .setDatabaseName(databaseName)
                .setLocation(Optional.of(location))
                .setOwnerName(ownerName)
                .setOwnerType(ownerType)
                .setParameters(parameters)
                .build();
    }
}

@@ -1132,52 +1132,8 @@
 pe;%0A
-    private final Optional%3CString%3E comment;%0A
     
@@ -1178,16 +1178,16 @@
 meters;%0A
+
 %0A    @Js
@@ -1445,71 +1445,8 @@
 pe,%0A
-            @JsonProperty(%22comment%22) Optional%3CString%3E comment,%0A
     
@@ -1754,75 +1754,8 @@
 %22);%0A
-        this.comment = requireNonNull(comment, %22comment is null%22);%0A
     
@@ -2134,54 +2134,8 @@
 ();%0A
-        this.comment = database.getComment();%0A
     
@@ -2463,32 +2463,32 @@
 nerType()%0A    %7B%0A
+
         return o
@@ -2508,104 +2508,8 @@
  %7D%0A%0A
-    @JsonProperty%0A    public Optional%3CString%3E getComment()%0A    %7B%0A        return comment;%0A    %7D%0A%0A
     

Remove unused database comment in file metastore