package mysql

import (
	"context"
	"time"

	"gorm.io/gorm"

	filemanager "wucher/internal/domain/file_manager"
)

func (r *FileManagerFileRepository) CreateFileStatusRealtimeEvent(ctx context.Context, input filemanager.FileStatusRealtimeEventInput) error {
	if r == nil || r.db == nil {
		return gorm.ErrInvalidDB
	}
	if input.OccurredAt.IsZero() {
		input.OccurredAt = time.Now().UTC()
	}
	row, err := filemanager.NewFileStatusRealtimeEvent(input)
	if err != nil {
		return err
	}
	return r.db.WithContext(ctx).Create(row).Error
}
