<?php

namespace Twnt4All\Engine\Mixin;

use Twnt4All\Engine\Contract\ConfigProviderInterface;
use Twnt4All\Engine\TwintCore;

trait ConfigAwareTrait
{
    /** @var ConfigProviderInterface */
    private $data_provider;

    private function log_event( $title, $event )
    {
        // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- captures the caller frame for structured logging; not a debug print.
        $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 );
        $caller    = array_shift( $backtrace );

        TwintCore::$logger::log_event( $title, $event, $this->data_provider, $caller );
    }

    private function log_error( $title, $error )
    {
        // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- captures the caller frame for structured logging; not a debug print.
        $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 );
        $caller    = array_shift( $backtrace );

        TwintCore::$logger::log_error( $title, $error, $this->data_provider, $caller );
    }
}