package logrepository

import (
	"legalgo-BE-go/database"
	logsdomain "legalgo-BE-go/internal/domain/logs"

	"github.com/google/uuid"
)

func (a *accessor) CreateLog(spec logsdomain.LogsSpec) error {
	newSpec := database.ContentLog{
		ID:        uuid.NewString(),
		ContentID: spec.ContentID,
		Category:  spec.Category,
	}

	if spec.UserID != nil {
		newSpec.UserID = *spec.UserID
	}

	if spec.IP != nil {
		newSpec.IP = *spec.IP
	}

	if spec.UserAgent != nil {
		newSpec.UserAgent = *spec.UserAgent
	}
	if err := a.db.Create(&newSpec).Error; err != nil {
		return err
	}

	return nil
}
