<?php

declare(strict_types=1);

namespace Apexl\Io\Logger\Dtos;

use Apexl\Utils\Strings\Camel;
use Spatie\DataTransferObject\DataTransferObject;
use stdClass;

abstract class HandlerConfigParams extends DataTransferObject
{
    public static function factory(string $destination, array $params): stdClass|HandlerConfigParams
    {
        $class = self::getHandlerConfigParamsClass($destination);

        return new $class($params);
    }

    private static function getHandlerConfigParamsClass(string $destination): string
    {
        $candidate = sprintf(
            '%s\\%sHandlerConfigParams',
            HandlerConfigParams::class,
            Camel::camelCase($destination)
        );

        return class_exists($candidate) ? $candidate : stdClass::class;
    }
}
