// codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/usecase/tag/gettagsforentity.go
package tag

import (
	"context"
	"fmt"

	"github.com/gocql/gocql"

	dom_tag "codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/domain/tag"
)

type GetTagsForEntityUseCase struct {
	tagRepo dom_tag.Repository
}

func NewGetTagsForEntityUseCase(tagRepo dom_tag.Repository) *GetTagsForEntityUseCase {
	return &GetTagsForEntityUseCase{
		tagRepo: tagRepo,
	}
}

func (uc *GetTagsForEntityUseCase) Execute(ctx context.Context, entityID gocql.UUID, entityType string) ([]*dom_tag.Tag, error) {
	// Validate entity type
	if entityType != dom_tag.EntityTypeCollection && entityType != dom_tag.EntityTypeFile {
		return nil, fmt.Errorf("invalid entity type: %s", entityType)
	}

	tags, err := uc.tagRepo.GetTagsForEntity(ctx, entityID, entityType)
	if err != nil {
		return nil, fmt.Errorf("failed to get tags for entity: %w", err)
	}

	return tags, nil
}
