<?php

declare(strict_types=1);

namespace Apexl\Tests\Core\FeatureTests\Relations;

use apexl\Io\TestInfrastructure\FeatureTest;
use app\module\newtonsTrailers\Entity\CollectionDelivery;
use app\module\newtonsTrailers\Entity\Company;
use app\module\newtonsTrailers\Entity\CompanyAddress;
use PHPUnit\Framework\Attributes\Test;

final class DistantRelationTest extends AbstractRelationTest
{
    #[Test]
    public function HasOneThroughHasOne(): void
    {
        $company = Company::factory()->create();
        $companyAddress = CompanyAddress::factory()->create(
            [
                'company_id' => $company->id
            ]
        );
        $collectionDelivery = CollectionDelivery::factory()->create(
            [
                'collection_company_id' => $company->id,
                'collection_address_id' => $companyAddress->id,
            ]
        );

        $found = CollectionDelivery::find($collectionDelivery->id, fields: [
            'collection_address.company.*',
        ]);

        $this->assertInstanceOf(Company::class, $found->collection_address->company);
    }


}