package database

import (
	"git.markbailey.dev/cervers/ptpp/lib/database/development"
	"git.markbailey.dev/cervers/ptpp/lib/database/production"
	"git.markbailey.dev/cervers/ptpp/lib/repository"
	"os"

	"git.markbailey.dev/cervers/ptpp/lib/logger"
)

type IDB interface {
	Info(string)
	Warn(string)
	Error(err error)
	Repo() repository.IRepository
}

func ChooseDB() IDB {
	l := logger.NewDBLogger()
	if os.Getenv("HTMX_APP_ENV") == "production" {
		db, err := production.NewProdDB(l)
		if err != nil {
			l.Error(l.Wrap(err, "Error creating production database"))
		}

		return db
	}

	db, err := development.NewTestDB(l)
	if err != nil {
		l.Error(l.Wrap(err, "Error creating test database"))
	}

	return db
}
