package app

import (
	"database/sql"

	"github.com/gorilla/mux"
	"github.com/jobs-scraper/api/commands/job"
	"github.com/jobs-scraper/infrastructure/rabbitmq"
	"github.com/jobs-scraper/internal/ports"
	"github.com/jobs-scraper/internal/repo"
	"github.com/jobs-scraper/internal/server"
)

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

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: job.NewCreateJobHandler(jobRepo, rmq),
		},
	}
}
