// codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/repo/user/anonymize_user_ips.go
package user

import (
	"context"
	"time"

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

// AnonymizeUserIPs immediately anonymizes all IP addresses for a specific user
// Used for GDPR right-to-be-forgotten implementation
func (impl *userStorerImpl) AnonymizeUserIPs(ctx context.Context, userID gocql.UUID) error {
	impl.logger.Info("Anonymizing IPs for specific user (GDPR mode)",
		zap.String("user_id", userID.String()))

	// Update the user record to anonymize all IP addresses
	query := `
		UPDATE maplefile.users_by_id
		SET created_from_ip_address = '0.0.0.0',
		    modified_from_ip_address = '0.0.0.0',
		    ip_anonymized_at = ?
		WHERE id = ?
	`

	if err := impl.session.Query(query, time.Now(), userID).WithContext(ctx).Exec(); err != nil {
		impl.logger.Error("Failed to anonymize user IPs",
			zap.String("user_id", userID.String()),
			zap.Error(err))
		return err
	}

	impl.logger.Info("✅ Successfully anonymized user IPs",
		zap.String("user_id", userID.String()))

	return nil
}
