<?php

namespace App\Tests\Entity;

use App\Entity\Customer;
use App\Entity\CustomerAddress;
use App\Entity\Devis;
use App\Entity\DevisLine;
use App\Entity\DevisOptions;
use PHPUnit\Framework\TestCase;

class DevisTest extends TestCase
{
    public function testGettersAndSetters()
    {
        $devis = new Devis();
        $customer = new Customer();
        $addressShip = new CustomerAddress();
        $billAddress = new CustomerAddress();
        $now = new \DateTimeImmutable();

        $devis->setCustomer($customer);
        $devis->setNum('DEVIS-001');
        $devis->setCreateA($now);
        $devis->setUpdateAt($now); // Use setUpdateAt
        $devis->setState('pending');
        $devis->setSignatureId('sign123');
        $devis->setAddressShip($addressShip);
        $devis->setBillAddress($billAddress);
        $devis->setStartAt($now->modify('+1 day'));
        $devis->setEndAt($now->modify('+2 days'));
        $devis->setDevisFileName('devis.pdf');
        $devis->setDevisFileSize(1024);
        $devis->setDevisDocuSealFileName('docuseal.pdf');
        $devis->setDevisDocuSealFileSize(2048);
        $devis->setDevisSignedFileName('signed.pdf');
        $devis->setDevisSignedFileSize(3072);
        $devis->setDevisAuditFileName('audit.pdf');
        $devis->setDevisAuditFileSize(4096);

        $this->assertSame($customer, $devis->getCustomer());
        $this->assertEquals('DEVIS-001', $devis->getNum());
        $this->assertEquals($now, $devis->getCreateA());
        $this->assertEquals($now, $devis->getUpdateAt()); // Use getUpdateAt
        $this->assertEquals('pending', $devis->getState());
        $this->assertEquals('sign123', $devis->getSignatureId());
        $this->assertSame($addressShip, $devis->getAddressShip());
        $this->assertSame($billAddress, $devis->getBillAddress());
        $this->assertEquals($now->modify('+1 day'), $devis->getStartAt());
        $this->assertEquals($now->modify('+2 days'), $devis->getEndAt());
        $this->assertEquals('devis.pdf', $devis->getDevisFileName());
        $this->assertEquals(1024, $devis->getDevisFileSize());
        $this->assertEquals('docuseal.pdf', $devis->getDevisDocuSealFileName());
        $this->assertEquals(2048, $devis->getDevisDocuSealFileSize());
        $this->assertEquals('signed.pdf', $devis->getDevisSignedFileName());
        $this->assertEquals(3072, $devis->getDevisSignedFileSize());
        $this->assertEquals('audit.pdf', $devis->getDevisAuditFileName());
        $this->assertEquals(4096, $devis->getDevisAuditFileSize());
    }

    public function testDevisLinesCollection()
    {
        $devis = new Devis();
        $line = new DevisLine();

        $this->assertCount(0, $devis->getDevisLines());
        $devis->addDevisLine($line);
        $this->assertCount(1, $devis->getDevisLines());
        $this->assertSame($devis, $line->getDevi()); // Use getDevi

        $devis->removeDevisLine($line);
        $this->assertCount(0, $devis->getDevisLines());
        $this->assertNull($line->getDevi()); // Use getDevi
    }

    public function testDevisOptionsCollection()
    {
        $devis = new Devis();
        $option = new DevisOptions();

        $this->assertCount(0, $devis->getDevisOptions());
        $devis->addDevisOption($option);
        $this->assertCount(1, $devis->getDevisOptions());
        $this->assertSame($devis, $option->getDevis());

        $devis->removeDevisOption($option);
        $this->assertCount(0, $devis->getDevisOptions());
        $this->assertNull($option->getDevis());
    }
}
