package Database

import (
	"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"

	"gorm.io/gorm/clause"
)

// GetSessionByID Gets session
func GetSessionByID(id string) (Models.Session, error) {
	var (
		session Models.Session
		err     error
	)

	err = DB.Preload(clause.Associations).
		First(&session, "id = ?", id).
		Error

	return session, err
}

// CreateSession creates session
func CreateSession(session *Models.Session) error {
	var (
		err error
	)

	err = DB.Create(session).Error

	return err
}

// DeleteSession deletes session
func DeleteSession(session *Models.Session) error {
	return DB.Delete(session).Error
}

// DeleteSessionByID deletes session
func DeleteSessionByID(id string) error {
	return DB.Delete(
		&Models.Session{},
		"id = ?",
		id,
	).Error
}
