package session

import (
	"time"

	"codeberg.org/mapleopentech/monorepo/native/desktop/maplefile/internal/domain/session"
)

type CreateUseCase struct {
	sessionRepo session.Repository
}

// ProvideCreateUseCase creates the use case for Wire
func ProvideCreateUseCase(sessionRepo session.Repository) *CreateUseCase {
	return &CreateUseCase{sessionRepo: sessionRepo}
}

// Execute creates and stores a new session
func (uc *CreateUseCase) Execute(
	userID, email, accessToken, refreshToken string,
	expiresIn time.Duration,
) error {
	sess := &session.Session{
		UserID:       userID,
		Email:        email,
		AccessToken:  accessToken,
		RefreshToken: refreshToken,
		ExpiresAt:    time.Now().Add(expiresIn),
		CreatedAt:    time.Now(),
	}

	return uc.sessionRepo.Save(sess)
}
