<?php
declare(strict_types=1);
require __DIR__ . '/bootstrap.php';

use Acbr\Contract;
use Acbr\Model\TDetCollection;
use Acbr\Model\TDetCollectionItem;
use Acbr\Model\TProd;

try {
    $original = (new TProd())->withCProd('TESTE')->withVProd('10.00');
    $changed = $original->withVProd('20.00');
    if ($original->getVProd() !== '10.00' || $changed->getVProd() !== '20.00') {
        throw new RuntimeException('Imutabilidade inesperada.');
    }

    $items = (new TDetCollection())->withItem((new TDetCollectionItem())->withProd($original));
    $second = $items->withItem((new TDetCollectionItem())->withProd($changed));
    if (count($items) !== 1 || count($second) !== 2 || $second->get(1)->getProd()?->getVProd() !== '20.00') {
        throw new RuntimeException('Colecao inesperada.');
    }
    Contract::bundled()->validate(acbrExampleDocument());
    acbrExamplePrint([
        'ambiente' => 'HOMOLOGACAO',
        'imutabilidade' => true,
        'colecaoOriginal' => count($items),
        'colecaoNova' => count($second),
        'tipos' => count(Contract::bundled()->types()),
        'semRede' => true,
    ]);
} catch (Throwable $error) {
    acbrExampleError($error);
    exit(1);
}
