package filemanager

import (
	"testing"

	"gorm.io/gorm"
)

func TestFolderTableName(t *testing.T) {
	var m Folder
	if got := m.TableName(); got != "file_folders" {
		t.Fatalf("table name mismatch: got %s", got)
	}
}

func TestFolderBeforeCreate(t *testing.T) {
	t.Run("assigns uuid when missing", func(t *testing.T) {
		m := &Folder{}
		if err := m.BeforeCreate(&gorm.DB{}); err != nil {
			t.Fatalf("before create error: %v", err)
		}
		if len(m.ID) != 16 {
			t.Fatalf("expected 16-byte id, got %d", len(m.ID))
		}
	})

	t.Run("keeps existing id", func(t *testing.T) {
		id := make([]byte, 16)
		for i := range id {
			id[i] = byte(i + 1)
		}
		m := &Folder{ID: append([]byte(nil), id...)}
		if err := m.BeforeCreate(&gorm.DB{}); err != nil {
			t.Fatalf("before create error: %v", err)
		}
		for i := range id {
			if m.ID[i] != id[i] {
				t.Fatalf("id changed at %d: got %d want %d", i, m.ID[i], id[i])
			}
		}
	})
}
