package database

import (
	_ "github.com/lib/pq"
)

//func DbConn(c HostDetails) (*sql.DB, error) {
//	var h string
//	var u string
//	var pw string
//	var dbn string
//	var psqlInfo string
//	h = c.Hostname
//	u = c.Username
//	pw = c.Secret
//	dbn = c.DatabaseName
//
//	logger.Logger("[LOG] connection details: host = " + h + " username = " + u)
//
//	found, testUserName := data.ViperPgmConfig("test_user", "r")
//	if found == true {
//		logger.Logger("[LOG] found test user in .pgm.yaml")
//	}
//	psqlInfo = fmt.Sprintf("host=%s port=%d user=%s "+
//		"password=%s dbname=%s sslmode=disable",
//		h, 5432, u, pw, dbn)
//	db, err := sql.Open("postgres", psqlInfo)
//	if err != nil {
//		var db *sql.DB
//		switch u {
//		case testUserName:
//			logger.Logger("[ERROR] go tests expects to connect with the docker compose database." +
//				"[ERROR] run \"docker-compose up\" and re-run tests")
//			err := errors.New("unable to ping db" + dbn + "local db is closed, please run docker-compose up")
//			return db, err
//		default:
//			logger.Logger("[ERROR] db error: " + err.Error())
//			return db, err
//		}
//
//	}
//	logger.Logger("[LOG] pinging db " + dbn)
//	ctx := context.Background()
//	err = db.PingContext(ctx)
//
//	if err != nil {
//		var db *sql.DB
//		switch u {
//		case testUserName:
//			logger.Logger("[ERROR] db error, unable to ping: " + err.Error()+
//				"\n[ERROR] ensure docker database is running and re-run tests")
//			fmt.Println("local db is closed, please run docker-compose up")
//			err1 := errors.New("unable to ping db" + dbn)
//			return db, err1
//		default:
//			logger.Logger("[ERROR] db error: " + err.Error())
//			return db, err
//		}
//	}
//	return db, nil
//}

type HostDetails struct {
	Secret       string `json:"secret"`
	Hostname     string `json:"hostname"`
	DatabaseName string `json:"databaseName"`
	Username     string `json:"username"`
}