package services

import (
	"net/http"

	"github.com/gorilla/sessions"
)

const sessionName = "maintainarr"

type SessionService struct {
	store *sessions.CookieStore
}

func NewSessionService(secret string) *SessionService {
	store := sessions.NewCookieStore([]byte(secret))
	store.Options = &sessions.Options{
		Path:     "/",
		HttpOnly: true,
		MaxAge:   86400 * 7,
		SameSite: http.SameSiteLaxMode,
	}

	return &SessionService{store: store}
}

func (s *SessionService) Get(r *http.Request) (*sessions.Session, error) {
	return s.store.Get(r, sessionName)
}
