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

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.trino.spi.type.TypeId;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.StringJoiner;

import static java.util.Objects.requireNonNull;

public class ConnectorMaterializedViewDefinition
{
    private final String originalSql;
    private final Optional<CatalogSchemaTableName> storageTable;
    private final Optional<String> catalog;
    private final Optional<String> schema;
    private final List<Column> columns;
    private final Optional<String> comment;
    private final String owner;
    private final Map<String, Object> properties;

    @JsonCreator
    public ConnectorMaterializedViewDefinition(
            @JsonProperty("originalSql") String originalSql,
            @JsonProperty("storageTable") Optional<CatalogSchemaTableName> storageTable,
            @JsonProperty("catalog") Optional<String> catalog,
            @JsonProperty("schema") Optional<String> schema,
            @JsonProperty("columns") List<Column> columns,
            @JsonProperty("comment") Optional<String> comment,
            @JsonProperty("owner") String owner,
            @JsonProperty("properties") Map<String, Object> properties)
    {
        this.originalSql = requireNonNull(originalSql, "originalSql is null");
        this.storageTable = requireNonNull(storageTable, "storageTable is null");
        this.catalog = requireNonNull(catalog, "catalog is null");
        this.schema = requireNonNull(schema, "schema is null");
        this.columns = List.copyOf(requireNonNull(columns, "columns is null"));
        this.comment = requireNonNull(comment, "comment is null");
        this.owner = requireNonNull(owner, "owner is null");

        if (catalog.isEmpty() && schema.isPresent()) {
            throw new IllegalArgumentException("catalog must be present if schema is present");
        }
        this.properties = requireNonNull(properties, "properties are null");
        if (columns.isEmpty()) {
            throw new IllegalArgumentException("columns list is empty");
        }
    }

    @JsonProperty
    public String getOriginalSql()
    {
        return originalSql;
    }

    @JsonProperty
    public Optional<CatalogSchemaTableName> getStorageTable()
    {
        return storageTable;
    }

    @JsonProperty
    public Optional<String> getCatalog()
    {
        return catalog;
    }

    @JsonProperty
    public Optional<String> getSchema()
    {
        return schema;
    }

    @JsonProperty
    public List<Column> getColumns()
    {
        return columns;
    }

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

    @JsonProperty
    public String getOwner()
    {
        return owner;
    }

    @JsonProperty
    public Map<String, Object> getProperties()
    {
        return properties;
    }

    @Override
    public String toString()
    {
        StringJoiner joiner = new StringJoiner(", ", "[", "]");
        joiner.add("originalSql=[" + originalSql + "]");
        storageTable.ifPresent(value -> joiner.add("storageTable=" + value));
        catalog.ifPresent(value -> joiner.add("catalog=" + value));
        schema.ifPresent(value -> joiner.add("schema=" + value));
        joiner.add("columns=" + columns);
        comment.ifPresent(value -> joiner.add("comment=" + value));
        joiner.add("owner=" + owner);
        joiner.add("properties=" + properties);
        return getClass().getSimpleName() + joiner.toString();
    }

    public static final class Column
    {
        private final String name;
        private final TypeId type;

        @JsonCreator
        public Column(
                @JsonProperty("name") String name,
                @JsonProperty("type") TypeId type)
        {
            this.name = requireNonNull(name, "name is null");
            this.type = requireNonNull(type, "type is null");
        }

        @JsonProperty
        public String getName()
        {
            return name;
        }

        @JsonProperty
        public TypeId getType()
        {
            return type;
        }

        @Override
        public String toString()
        {
            return name + " " + type;
        }
    }
}

@@ -592,115 +592,8 @@
 r;%0A%0A
-import com.fasterxml.jackson.annotation.JsonCreator;%0Aimport com.fasterxml.jackson.annotation.JsonProperty;%0A
 impo
@@ -621,16 +621,16 @@
 TypeId;%0A
+
 %0Aimport 
@@ -1183,33 +1183,16 @@
 rties;%0A%0A
-    @JsonCreator%0A
     publ
@@ -1246,37 +1246,8 @@
     
- @JsonProperty(%22originalSql%22)
  Str
@@ -1278,38 +1278,8 @@
     
- @JsonProperty(%22storageTable%22)
  Opt
@@ -1337,33 +1337,8 @@
     
- @JsonProperty(%22catalog%22)
  Opt
@@ -1375,32 +1375,8 @@
     
- @JsonProperty(%22schema%22)
  Opt
@@ -1412,33 +1412,8 @@
     
- @JsonProperty(%22columns%22)
  Lis
@@ -1446,33 +1446,8 @@
     
- @JsonProperty(%22comment%22)
  Opt
@@ -1484,31 +1484,8 @@
     
- @JsonProperty(%22owner%22)
  Str
@@ -1510,36 +1510,8 @@
     
- @JsonProperty(%22properties%22)
  Map
@@ -2407,34 +2407,16 @@
 %0A    %7D%0A%0A
-    @JsonProperty%0A
     publ
@@ -2483,34 +2483,16 @@
 %0A    %7D%0A%0A
-    @JsonProperty%0A
     publ
@@ -2587,34 +2587,16 @@
 %0A    %7D%0A%0A
-    @JsonProperty%0A
     publ
@@ -2665,34 +2665,16 @@
 %0A    %7D%0A%0A
-    @JsonProperty%0A
     publ
@@ -2741,34 +2741,16 @@
 %0A    %7D%0A%0A
-    @JsonProperty%0A
     publ
@@ -2815,34 +2815,16 @@
 %0A    %7D%0A%0A
-    @JsonProperty%0A
     publ
@@ -2893,34 +2893,16 @@
 %0A    %7D%0A%0A
-    @JsonProperty%0A
     publ
@@ -2957,34 +2957,16 @@
 %0A    %7D%0A%0A
-    @JsonProperty%0A
     publ
@@ -3810,29 +3810,8 @@
 e;%0A%0A
-        @JsonCreator%0A
     
@@ -3832,97 +3832,20 @@
 umn(
-%0A                @JsonProperty(%22name%22) String name,%0A                @JsonProperty(%22type%22)
+String name,
  Typ
@@ -3999,38 +3999,16 @@
      %7D%0A%0A
-        @JsonProperty%0A
         
@@ -4081,30 +4081,8 @@
  %7D%0A%0A
-        @JsonProperty%0A
     

Remove json annotations from ConnectorMaterializedViewDefinition