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

import llc.arma.fleet.monitor.data.entity.BeaconEntity
import llc.arma.fleet.monitor.data.entity.DepartmentEntity
import llc.arma.fleet.monitor.data.entity.MachineTypeEntity
import llc.arma.fleet.monitor.domain.service.ReferenceService
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

@Controller
class ReferenceGraphQlController(
    private val referenceService: ReferenceService,
) {
    @QueryMapping
    fun getMachineTypes(): List<MachineTypeEntity> = referenceService.getMachineTypes()

    @QueryMapping
    fun getDepartments(): List<DepartmentEntity> = referenceService.getDepartments()

    @QueryMapping
    fun getBeacons(): List<BeaconEntity> = referenceService.getBeacons()

    @QueryMapping
    fun getFreeBeacons(): List<BeaconEntity> = referenceService.getFreeBeacons()

    @MutationMapping
    fun createMachineType(@Argument name: String): MachineTypeEntity = referenceService.createMachineType(name)

    @MutationMapping
    fun updateMachineType(@Argument id: Long, @Argument name: String): MachineTypeEntity = referenceService.updateMachineType(id, name)

    @MutationMapping
    fun deleteMachineType(@Argument id: Long): Boolean = referenceService.deleteMachineType(id)

    @MutationMapping
    fun createDepartment(@Argument name: String): DepartmentEntity = referenceService.createDepartment(name)

    @MutationMapping
    fun updateDepartment(@Argument id: Long, @Argument name: String): DepartmentEntity = referenceService.updateDepartment(id, name)

    @MutationMapping
    fun deleteDepartment(@Argument id: Long): Boolean = referenceService.deleteDepartment(id)
}
