package service

import (
	"context"
	"log"

	"github.com/calendarapi/internal/repository"
	"github.com/calendarapi/internal/utils"
	"github.com/google/uuid"
)

type AuditService struct {
	queries *repository.Queries
}

func NewAuditService(queries *repository.Queries) *AuditService {
	return &AuditService{queries: queries}
}

func (s *AuditService) Log(ctx context.Context, entityType string, entityID uuid.UUID, action string, userID uuid.UUID) {
	err := s.queries.CreateAuditLog(ctx, repository.CreateAuditLogParams{
		EntityType: entityType,
		EntityID:   utils.ToPgUUID(entityID),
		Action:     action,
		UserID:     utils.ToPgUUID(userID),
	})
	if err != nil {
		log.Printf("audit log failed: entity=%s id=%s action=%s err=%v", entityType, entityID, action, err)
	}
}
