<?php

declare (strict_types=1);
/**
 * Creates Decoder objects
 *
 * PHP version 5.4
 *
 * @category LibDNS
 * @package Decoder
 * @author Chris Wright <https://github.com/DaveRandom>
 * @copyright Copyright (c) Chris Wright <https://github.com/DaveRandom>
 * @license http://www.opensource.org/licenses/mit-license.html MIT License
 * @version 2.0.0
 */
namespace GDAVSCOPE\LibDNS\Decoder;

use GDAVSCOPE\LibDNS\Packets\PacketFactory;
use GDAVSCOPE\LibDNS\Messages\MessageFactory;
use GDAVSCOPE\LibDNS\Records\RecordCollectionFactory;
use GDAVSCOPE\LibDNS\Records\QuestionFactory;
use GDAVSCOPE\LibDNS\Records\ResourceBuilder;
use GDAVSCOPE\LibDNS\Records\ResourceFactory;
use GDAVSCOPE\LibDNS\Records\RDataBuilder;
use GDAVSCOPE\LibDNS\Records\RDataFactory;
use GDAVSCOPE\LibDNS\Records\Types\TypeBuilder;
use GDAVSCOPE\LibDNS\Records\Types\TypeFactory;
use GDAVSCOPE\LibDNS\Records\TypeDefinitions\TypeDefinitionManager;
use GDAVSCOPE\LibDNS\Records\TypeDefinitions\TypeDefinitionFactory;
use GDAVSCOPE\LibDNS\Records\TypeDefinitions\FieldDefinitionFactory;
/**
 * Creates Decoder objects
 *
 * @category LibDNS
 * @package Decoder
 * @author Chris Wright <https://github.com/DaveRandom>
 */
class DecoderFactory
{
    /**
     * Create a new Decoder object
     *
     * @param \LibDNS\Records\TypeDefinitions\TypeDefinitionManager $typeDefinitionManager
     * @param bool $allowTrailingData
     * @return Decoder
     */
    public function create(?TypeDefinitionManager $typeDefinitionManager = null, bool $allowTrailingData = \true): Decoder
    {
        $typeBuilder = new TypeBuilder(new TypeFactory());
        return new Decoder(new PacketFactory(), new MessageFactory(new RecordCollectionFactory()), new QuestionFactory(), new ResourceBuilder(new ResourceFactory(), new RDataBuilder(new RDataFactory(), $typeBuilder), $typeDefinitionManager ?: new TypeDefinitionManager(new TypeDefinitionFactory(), new FieldDefinitionFactory())), $typeBuilder, new DecodingContextFactory(), $allowTrailingData);
    }
}
