package main

import (
	"git.javil.eu/jacob1123/budgeteer/bcrypt"
	"git.javil.eu/jacob1123/budgeteer/config"
	"git.javil.eu/jacob1123/budgeteer/http"
	"git.javil.eu/jacob1123/budgeteer/jwt"
	"git.javil.eu/jacob1123/budgeteer/postgres"
	"git.javil.eu/jacob1123/budgeteer/ulid"
)

func main() {
	cfg, err := config.LoadConfig()
	if err != nil {
		panic("Could not load Config")
	}

	bv := &bcrypt.Verifier{}
	db := postgres.Connect(cfg.DatabaseHost, cfg.DatabaseUser, cfg.DatabasePassword, cfg.DatabaseName)
	id, err := ulid.NewGenerator()
	if err != nil {
		panic("Failed creating ID-Generator")
	}

	us := &postgres.Repository{DB: db, IDGenerator: id}
	tv := &jwt.TokenVerifier{}

	h := &http.Handler{
		Service:             us,
		TokenVerifier:       tv,
		CredentialsVerifier: bv,
	}
	h.Serve()
}
