module Jerimum.Tests.Integration.PostgreSQL.Types.DateTimeTests where

import Jerimum.PostgreSQL.Types.DateTime
import Jerimum.Tests.Integration.DataTypeHelper
import Jerimum.Tests.Integration.Resource
import Test.Tasty

tests :: TestTree
tests =
  testGroup
    "DATETIME"
    [ testGroup
        "data type"
        [ buildTest
            (testDataType
               "timestamp"
               ( fromTimestampNoTz Nothing
               , fromTimestampNoTz (Just ((1970, 1, 1), (0, 0, 0, 123456)))
               , "1970-01-01 00:00:00.123456" :: String))
        , buildTest
            (testDataType
               "timestamp(6)"
               ( fromTimestampNoTz Nothing
               , fromTimestampNoTz (Just ((1970, 1, 1), (0, 0, 0, 123456)))
               , "1970-01-01 00:00:00.123456" :: String))
        , buildTest
            (testDataType
               "timestamp without time zone"
               ( fromTimestampNoTz Nothing
               , fromTimestampNoTz (Just ((1970, 1, 1), (0, 0, 0, 123456)))
               , "1970-01-01 00:00:00.123456" :: String))
        , buildTest
            (testDataType
               "timestamp(6) without time zone"
               ( fromTimestampNoTz Nothing
               , fromTimestampNoTz (Just ((1970, 1, 1), (0, 0, 0, 123456)))
               , "1970-01-01 00:00:00.123456" :: String))
        , buildTest
            (testDataType
               "timestamptz"
               ( fromTimestampTz Nothing
               , fromTimestampTz
                   (Just ((1970, 1, 1), (3, 0, 0, 123456), (0, 0)))
               , "1970-01-01 00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataType
               "timestamptz(6)"
               ( fromTimestampTz Nothing
               , fromTimestampTz
                   (Just ((1970, 1, 1), (3, 0, 0, 123456), (0, 0)))
               , "1970-01-01 00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataType
               "timestamp with time zone"
               ( fromTimestampTz Nothing
               , fromTimestampTz
                   (Just ((1970, 1, 1), (3, 0, 0, 123456), (0, 0)))
               , "1970-01-01 00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataType
               "timestamp(6) with time zone"
               ( fromTimestampTz Nothing
               , fromTimestampTz
                   (Just ((1970, 1, 1), (3, 0, 0, 123456), (0, 0)))
               , "1970-01-01 00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataType
               "date"
               ( fromDate Nothing
               , fromDate (Just (1970, 1, 1))
               , "1970-01-01" :: String))
        , buildTest
            (testDataType
               "time"
               ( fromTimeNoTz Nothing
               , fromTimeNoTz (Just (0, 0, 0, 123456))
               , "00:00:00.123456" :: String))
        , buildTest
            (testDataType
               "time(6)"
               ( fromTimeNoTz Nothing
               , fromTimeNoTz (Just (0, 0, 0, 123456))
               , "00:00:00.123456" :: String))
        , buildTest
            (testDataType
               "time(6) without time zone"
               ( fromTimeNoTz Nothing
               , fromTimeNoTz (Just (0, 0, 0, 123456))
               , "00:00:00.123456" :: String))
        , buildTest
            (testDataType
               "timetz"
               ( fromTimeTz Nothing
               , fromTimeTz (Just ((0, 0, 0, 123456), (-3, 0)))
               , "00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataType
               "timetz(6)"
               ( fromTimeTz Nothing
               , fromTimeTz (Just ((0, 0, 0, 123456), (-3, 0)))
               , "00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataType
               "time(6) with time zone"
               ( fromTimeTz Nothing
               , fromTimeTz (Just ((0, 0, 0, 123456), (-3, 0)))
               , "00:00:00.123456-03:00" :: String))
        ]
    , testGroup
        "from field"
        [ buildTest
            (testDataTypeFromField
               "timestamp"
               ( fromTimestampNoTz Nothing
               , fromTimestampNoTz (Just ((1970, 1, 1), (0, 0, 0, 123456)))
               , "1970-01-01 00:00:00.123456" :: String))
        , buildTest
            (testDataTypeFromField
               "timestamp(6)"
               ( fromTimestampNoTz Nothing
               , fromTimestampNoTz (Just ((1970, 1, 1), (0, 0, 0, 123456)))
               , "1970-01-01 00:00:00.123456" :: String))
        , buildTest
            (testDataTypeFromField
               "timestamp without time zone"
               ( fromTimestampNoTz Nothing
               , fromTimestampNoTz (Just ((1970, 1, 1), (0, 0, 0, 123456)))
               , "1970-01-01 00:00:00.123456" :: String))
        , buildTest
            (testDataTypeFromField
               "timestamp(6) without time zone"
               ( fromTimestampNoTz Nothing
               , fromTimestampNoTz (Just ((1970, 1, 1), (0, 0, 0, 123456)))
               , "1970-01-01 00:00:00.123456" :: String))
        , buildTest
            (testDataTypeFromField
               "timestamptz"
               ( fromTimestampTz Nothing
               , fromTimestampTz
                   (Just ((1970, 1, 1), (3, 0, 0, 123456), (0, 0)))
               , "1970-01-01 00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataTypeFromField
               "timestamptz(6)"
               ( fromTimestampTz Nothing
               , fromTimestampTz
                   (Just ((1970, 1, 1), (3, 0, 0, 123456), (0, 0)))
               , "1970-01-01 00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataTypeFromField
               "timestamp with time zone"
               ( fromTimestampTz Nothing
               , fromTimestampTz
                   (Just ((1970, 1, 1), (3, 0, 0, 123456), (0, 0)))
               , "1970-01-01 00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataTypeFromField
               "timestamp(6) with time zone"
               ( fromTimestampTz Nothing
               , fromTimestampTz
                   (Just ((1970, 1, 1), (3, 0, 0, 123456), (0, 0)))
               , "1970-01-01 00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataTypeFromField
               "date"
               ( fromDate Nothing
               , fromDate (Just (1970, 1, 1))
               , "1970-01-01" :: String))
        , buildTest
            (testDataTypeFromField
               "time"
               ( fromTimeNoTz Nothing
               , fromTimeNoTz (Just (0, 0, 0, 123456))
               , "00:00:00.123456" :: String))
        , buildTest
            (testDataTypeFromField
               "time(6)"
               ( fromTimeNoTz Nothing
               , fromTimeNoTz (Just (0, 0, 0, 123456))
               , "00:00:00.123456" :: String))
        , buildTest
            (testDataTypeFromField
               "time(6) without time zone"
               ( fromTimeNoTz Nothing
               , fromTimeNoTz (Just (0, 0, 0, 123456))
               , "00:00:00.123456" :: String))
        , buildTest
            (testDataTypeFromField
               "timetz"
               ( fromTimeTz Nothing
               , fromTimeTz (Just ((0, 0, 0, 123456), (-3, 0)))
               , "00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataTypeFromField
               "timetz(6)"
               ( fromTimeTz Nothing
               , fromTimeTz (Just ((0, 0, 0, 123456), (-3, 0)))
               , "00:00:00.123456-03:00" :: String))
        , buildTest
            (testDataTypeFromField
               "time(6) with time zone"
               ( fromTimeTz Nothing
               , fromTimeTz (Just ((0, 0, 0, 123456), (-3, 0)))
               , "00:00:00.123456-03:00" :: String))
        ]
    ]
