package llc.arma.fleet.monitor.presentation.graphql

import llc.arma.fleet.monitor.data.entity.BeaconTelemetryPacketEntity
import llc.arma.fleet.monitor.domain.service.TelemetryService
import llc.arma.fleet.monitor.presentation.model.BeaconTelemetryPayload
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.MutationMapping
import org.springframework.graphql.data.method.annotation.QueryMapping
import org.springframework.stereotype.Controller
import java.time.OffsetDateTime

@Controller
class TelemetryGraphQlController(
    private val telemetryService: TelemetryService,
) {
    @QueryMapping
    fun getBeaconTelemetry(
        @Argument beaconId: Long?,
        @Argument machineId: Long?,
        @Argument startDate: OffsetDateTime,
        @Argument endDate: OffsetDateTime,
    ): List<BeaconTelemetryPacketEntity> = telemetryService.getBeaconTelemetry(beaconId, machineId, startDate, endDate)

    @MutationMapping
    fun registerBeaconTelemetryPacket(@Argument payload: BeaconTelemetryPayload): Boolean =
        telemetryService.registerBeaconTelemetryPacket(payload)
}
