package page

import (
	"context"
	"fmt"

	"github.com/gocql/gocql"
	"go.uber.org/zap"

	domainpage "codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/internal/domain/page"
)

// GetPageByIDUseCase retrieves a specific page by ID
type GetPageByIDUseCase struct {
	pageRepo domainpage.Repository
	logger   *zap.Logger
}

// ProvideGetPageByIDUseCase creates a new GetPageByIDUseCase
func ProvideGetPageByIDUseCase(
	pageRepo domainpage.Repository,
	logger *zap.Logger,
) *GetPageByIDUseCase {
	return &GetPageByIDUseCase{
		pageRepo: pageRepo,
		logger:   logger,
	}
}

// Execute retrieves a page by its ID
func (uc *GetPageByIDUseCase) Execute(
	ctx context.Context,
	siteID gocql.UUID,
	pageID string,
) (*domainpage.Page, error) {
	// Get page from database
	page, err := uc.pageRepo.GetByID(ctx, siteID, pageID)
	if err != nil {
		uc.logger.Error("failed to get page",
			zap.String("page_id", pageID),
			zap.Error(err))
		return nil, fmt.Errorf("page not found")
	}

	uc.logger.Info("page retrieved",
		zap.String("site_id", siteID.String()),
		zap.String("page_id", pageID))

	return page, nil
}
