package analytic

import (
	"context"
	"fmt"

	"git.gocasts.ir/ebhomengo/niki/patientapp/config"
	"git.gocasts.ir/ebhomengo/niki/repository/mysql"
)

type Server struct {
	HTTPServer *config.EchoServer
	Db         *mysql.DB
}

func NewServer(server *config.EchoServer, db *mysql.DB) *Server {

	return &Server{
		HTTPServer: server,
		Db:         db,
	}
}

func (s Server) Serve() error {
	s.RegisterRoutes()
	// Start server
	return s.HTTPServer.Router.Start(fmt.Sprintf(":%d", s.HTTPServer.Config.Port))
}

func (s Server) Stop(ctx context.Context) error {
	return s.HTTPServer.Router.Shutdown(ctx)

}

func (s Server) RegisterRoutes() {

	v1 := s.HTTPServer.Router.Group("/v1")
	{
		// Analytic Group
		analyticGroup := v1.Group("/analytic")
		NewPatientAnalyticRouter(analyticGroup, s.Db)
	}

}
