package llc.arma.fleet.monitor.config

import graphql.scalars.ExtendedScalars
import graphql.schema.GraphQLScalarType
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.graphql.execution.RuntimeWiringConfigurer
import java.time.LocalDate
import java.time.OffsetDateTime

@Configuration
class GraphQlConfig {
    @Bean
    fun runtimeWiringConfigurer(): RuntimeWiringConfigurer = RuntimeWiringConfigurer { wiringBuilder ->
        wiringBuilder.scalar(ExtendedScalars.GraphQLLong)
        wiringBuilder.scalar(dateTimeScalar())
        wiringBuilder.scalar(dateScalar())
    }

    private fun dateTimeScalar(): GraphQLScalarType = ExtendedScalars.newAliasedScalar("DateTime")
        .aliasedScalar(ExtendedScalars.DateTime)
        .build()

    private fun dateScalar(): GraphQLScalarType = ExtendedScalars.newAliasedScalar("Date")
        .aliasedScalar(ExtendedScalars.Date)
        .build()
}
