package webdebug

import (
	"context"
	"net/http"
)

const DebugAddr = "127.0.0.1:3305"

type Server struct {
	server *http.Server
}

func New() *Server {
	handler := http.NewServeMux()
	handler.HandleFunc("GET /non-deleted", getNonDeletedUsers)
	handler.HandleFunc("POST /local-user", createLocalUser)
	handler.HandleFunc("GET /delete", deleteUser)
	web := http.Server{
		Addr:    DebugAddr,
		Handler: handler,
	}
	return &Server{&web}
}

func (s *Server) Start() error {
	if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
		return err
	}
	return nil
}

func (s *Server) Stop() error {
	return s.server.Shutdown(context.Background())
}
