/*
 * 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.prestosql.plugin.base.session;

import io.airlift.units.DataSize;
import io.airlift.units.Duration;
import io.prestosql.spi.session.PropertyMetadata;

import static io.prestosql.spi.type.VarcharType.VARCHAR;

public final class PropertyMetadataUtil
{
    private PropertyMetadataUtil() {}

    public static PropertyMetadata<DataSize> dataSizeProperty(String name, String description, DataSize defaultValue, boolean hidden)
    {
        return new PropertyMetadata<>(
                name,
                description,
                VARCHAR,
                DataSize.class,
                defaultValue,
                hidden,
                value -> DataSize.valueOf((String) value),
                DataSize::toString);
    }

    public static PropertyMetadata<Duration> durationProperty(String name, String description, Duration defaultValue, boolean hidden)
    {
        return new PropertyMetadata<>(
                name,
                description,
                VARCHAR,
                Duration.class,
                defaultValue,
                hidden,
                value -> Duration.valueOf((String) value),
                Duration::toString);
    }
}

@@ -717,16 +717,53 @@
 adata;%0A%0A
+import java.util.function.Consumer;%0A%0A
 import s
@@ -1025,32 +1025,297 @@
 n hidden)%0A    %7B%0A
+        return dataSizeProperty(name, description, defaultValue, value -%3E %7B%7D, hidden);%0A    %7D%0A%0A    public static PropertyMetadata%3CDataSize%3E dataSizeProperty(String name, String description, DataSize defaultValue, Consumer%3CDataSize%3E validation, boolean hidden)%0A    %7B%0A
         return n
@@ -1515,24 +1515,64 @@
         
+object -%3E %7B%0A                    DataSize 
 value 
--%3E
+=
  DataSiz
@@ -1582,38 +1582,138 @@
 alueOf((String) 
-value)
+object);%0A                    validation.accept(value);%0A                    return value;%0A                %7D
 ,%0A              
@@ -1874,32 +1874,297 @@
 n hidden)%0A    %7B%0A
+        return durationProperty(name, description, defaultValue, value -%3E %7B%7D, hidden);%0A    %7D%0A%0A    public static PropertyMetadata%3CDuration%3E durationProperty(String name, String description, Duration defaultValue, Consumer%3CDuration%3E validation, boolean hidden)%0A    %7B%0A
         return n
@@ -2364,24 +2364,64 @@
         
+object -%3E %7B%0A                    Duration 
 value 
--%3E
+=
  Duratio
@@ -2439,22 +2439,122 @@
 String) 
-value)
+object);%0A                    validation.accept(value);%0A                    return value;%0A                %7D
 ,%0A      

Add methods for defining session properties with validation