package query

import (
	"testing"

	"github.com/stretchr/testify/assert"

	"github.com/photoprism/photoprism/internal/entity"
)

func TestFolderCoverByUID(t *testing.T) {
	t.Run("Num1990Num04", func(t *testing.T) {
		if result, err := FolderCoverByUID("dqo63pn2f87f02xj"); err != nil {
			t.Fatal(err)
		} else if result.FileUID == "" {
			t.Fatal("result must not be empty")
		} else if result.FileUID != "fs6sg6bw15bnlqdw" {
			t.Errorf("wrong result: %#v", result)
		}
	})
	t.Run("Num2007Twelve", func(t *testing.T) {
		if result, err := FolderCoverByUID("dqo63pn2f87f02oi"); err != nil {
			t.Fatal(err)
		} else if result.FileUID == "" {
			t.Fatal("result must not be empty")
		} else if result.FileUID != "fs6sg6bqhhinlplk" {
			t.Errorf("wrong result: %#v", result)
		}
	})
}

func TestFoldersByPath(t *testing.T) {
	t.Run("Root", func(t *testing.T) {
		folders, err := FoldersByPath(entity.RootOriginals, "testdata", "", false)

		t.Logf("folders: %+v", folders)

		if err != nil {
			t.Fatal(err)
		}

		assert.Len(t, folders, 1)
	})
	t.Run("Subdirectory", func(t *testing.T) {
		folders, err := FoldersByPath(entity.RootOriginals, "testdata", "directory", false)

		t.Logf("folders: %+v", folders)

		if err != nil {
			t.Fatal(err)
		}

		assert.Len(t, folders, 2)
	})
}

func TestAlbumFolders(t *testing.T) {
	t.Run("Root", func(t *testing.T) {
		folders, err := AlbumFolders(1)

		if err != nil {
			t.Fatal(err)
		}
		assert.GreaterOrEqual(t, len(folders), 1)

		t.Logf("folders: %+v", folders)
	})
}

func TestUpdateFolderDates(t *testing.T) {
	t.Run("Success", func(t *testing.T) {
		if err := UpdateFolderDates(); err != nil {
			t.Fatal(err)
		}
	})
}
