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

import io.trino.operator.scalar.AbstractTestFunctions;
import io.trino.spi.type.SqlTimestampWithTimeZone;
import io.trino.spi.type.TimeZoneKey;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.time.ZonedDateTime;

import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS;
import static java.time.ZoneOffset.UTC;

public class TestObjectIdFunctions
        extends AbstractTestFunctions
{
    @BeforeClass
    protected void registerFunctions()
    {
        functionAssertions.installPlugin(new MongoPlugin());
    }

    @Test
    public void testObjectidTimestamp()
    {
        assertFunction(
                "objectid_timestamp(ObjectId('1234567890abcdef12345678'))",
                TIMESTAMP_TZ_MILLIS,
                toTimestampWithTimeZone(ZonedDateTime.of(1979, 9, 5, 22, 51, 36, 0, UTC)));
    }

    private SqlTimestampWithTimeZone toTimestampWithTimeZone(ZonedDateTime zonedDateTime)
    {
        return SqlTimestampWithTimeZone.newInstance(3, zonedDateTime.toInstant().toEpochMilli(), 0, TimeZoneKey.getTimeZoneKey(zonedDateTime.getZone().getId()));
    }
}

@@ -720,27 +720,98 @@
 pi.type.
-TimeZoneKey
+SqlVarbinary;%0Aimport io.trino.spi.type.TimeZoneKey;%0Aimport org.bson.types.ObjectId
 ;%0Aimport
@@ -917,16 +917,78 @@
 eTime;%0A%0A
+import static io.trino.plugin.mongodb.ObjectIdType.OBJECT_ID;%0A
 import s
@@ -1228,32 +1228,32 @@
 nctions()%0A    %7B%0A
-
         function
@@ -1300,24 +1300,554 @@
 ());%0A    %7D%0A%0A
+    @Test%0A    public void testObjectid()%0A    %7B%0A        assertFunction(%0A                %22ObjectId('1234567890abcdef12345678')%22,%0A                OBJECT_ID,%0A                new SqlVarbinary(new ObjectId(%221234567890abcdef12345678%22).toByteArray()));%0A    %7D%0A%0A    @Test%0A    public void testObjectidIgnoresSpaces()%0A    %7B%0A        assertFunction(%0A                %22ObjectId('12 34 56 78 90 ab cd ef   12 34 56 78')%22,%0A                OBJECT_ID,%0A                new SqlVarbinary(new ObjectId(%221234567890abcdef12345678%22).toByteArray()));%0A    %7D%0A%0A
     @Test%0A  

Add test for MongoDB ObjectId