package server

import (
	"strings"

	"github.com/kataras/iris/v12"
	"github.com/rs/zerolog/log"
	"pluja.dev/kycnot.me/database"
)

func (s *Server) handleApiService(c iris.Context) {
	serviceName := strings.ToLower(c.Params().Get("name"))

	service, err := database.Pb.GetServiceByNameOrUrl(serviceName)
	if err != nil {
		log.Error().Err(err).Msgf("Could not get service %v from database", serviceName)
		c.HTML("<h3>%s</h3>", err.Error())
		return
	}

	// Return the service as JSON
	c.JSON(service)
}
