package storagedailyusage

import (
	"context"

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

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

// DeleteByUserUseCase deletes all storage daily usage records for a user
// Used for GDPR right-to-be-forgotten implementation
type DeleteByUserUseCase interface {
	Execute(ctx context.Context, userID gocql.UUID) error
}

type deleteByUserUseCaseImpl struct {
	logger *zap.Logger
	repo   storagedailyusage.StorageDailyUsageRepository
}

// NewDeleteByUserUseCase creates a new use case for deleting all storage daily usage by user ID
func NewDeleteByUserUseCase(
	logger *zap.Logger,
	repo storagedailyusage.StorageDailyUsageRepository,
) DeleteByUserUseCase {
	return &deleteByUserUseCaseImpl{
		logger: logger.Named("DeleteStorageDailyUsageByUserUseCase"),
		repo:   repo,
	}
}

func (uc *deleteByUserUseCaseImpl) Execute(ctx context.Context, userID gocql.UUID) error {
	uc.logger.Info("Deleting all storage daily usage for user",
		zap.String("user_id", userID.String()))

	err := uc.repo.DeleteByUserID(ctx, userID)
	if err != nil {
		uc.logger.Error("Failed to delete storage daily usage",
			zap.String("user_id", userID.String()),
			zap.Error(err))
		return err
	}

	uc.logger.Info("✅ Successfully deleted all storage daily usage for user",
		zap.String("user_id", userID.String()))

	return nil
}
