package gallery

import (
	"time"

	"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/images"
	"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
	"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/filesystem"
	"github.com/valkey-io/valkey-go"
)

type getImager interface {
	GetImage(path string) (img images.Image, err error)
}

type Service struct {
	fs    filesystem.FS
	cfg   *config.Gallery
	img   getImager
	cache valkey.Client

	refreshIntervall time.Duration
}

func New(fs filesystem.FS, cfg *config.Gallery, img getImager, cache valkey.Client) *Service {
	s := &Service{
		fs:    fs,
		cfg:   cfg,
		img:   img,
		cache: cache,
	}
	go s.autoRefresh()

	return s
}
