package app

import (
	"database/sql"

	"github.com/gorilla/mux"
	"github.com/jobs-scraper/internal/pkg/infrastructure/rabbitmq"
	"github.com/jobs-scraper/libs/ports"
	"github.com/jobs-scraper/libs/repo"
	"github.com/jobs-scraper/libs/server"
	jobCommands "github.com/jobs-scraper/services/api/internal/commands/job"
	jobQueries "github.com/jobs-scraper/services/api/internal/queries/job"
)

type Application struct {
	Router      *mux.Router
	DB          *sql.DB
	Server      *server.AppServer
	JobCommands *ports.JobCommands
	JobQueries  *ports.JobQueries
}

func NewApplication(router *mux.Router, db *sql.DB, rmq *rabbitmq.RabbitMQClient) *Application {
	s := server.NewServer(router)

	jobRepo := repo.NewJobRepository(db)

	return &Application{
		Server: s,
		Router: router,
		DB:     db,
		JobCommands: &ports.JobCommands{
			CreateJob: jobCommands.NewCreateJobHandler(jobRepo, rmq),
		},
		JobQueries: &ports.JobQueries{
			GetJobs: jobQueries.NewGetJobsHandler(jobRepo),
		},
	}
}
