<?php

namespace App\Tests\Entity;

use App\Entity\Contrats;
use App\Entity\Customer;
use App\Entity\CustomerAddress;
use App\Entity\CustomerTracking;
use App\Entity\Devis;
use App\Entity\OrderSession;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Uid\Uuid;

class CustomerTest extends TestCase
{
    public function testGettersAndSetters()
    {
        $customer = new Customer();
        $now = new \DateTimeImmutable();
        $uuid = Uuid::v4();

        $customer->setEmail('customer@test.com');
        $customer->setRoles(['ROLE_CUSTOMER']);
        $customer->setPassword('hash');
        // $customer->setCreateAt($now); // No setCreateAt
        // $customer->setIsVerified(true); // No isVerified
        // $customer->setRgpd(true); // No Rgpd
        // $customer->setNewsLetter(true); // No NewsLetter
        // $customer->setIsActive(true); // No IsActive
        $customer->setIsAccountConfigured(true);
        $customer->setName('Doe');
        $customer->setSurname('John');
        $customer->setPhone('0123456789');
        // $customer->setBirthday(new \DateTime('1990-01-01')); // No Birthday
        $customer->setCiv('Mr');
        $customer->setSiret('12345678901234');
        // $customer->setKbis('kbis_file'); // No Kbis
        // $customer->setUpdatedAt($now); // No UpdatedAt
        $customer->setCustomerId('cust_id_123');
        $customer->setVerificationCode('123456');
        $customer->setVerificationCodeExpiresAt($now->modify('+10min'));

        $this->assertEquals('customer@test.com', $customer->getEmail());
        $this->assertContains('ROLE_CUSTOMER', $customer->getRoles());
        $this->assertEquals('hash', $customer->getPassword());
        // $this->assertNotNull($customer->getCreateAt()); // Constructor sets it
        $this->assertTrue($customer->isAccountConfigured());
        $this->assertEquals('Doe', $customer->getName());
        $this->assertEquals('John', $customer->getSurname());
        $this->assertEquals('0123456789', $customer->getPhone());
        $this->assertEquals('Mr', $customer->getCiv());
        $this->assertEquals('12345678901234', $customer->getSiret());
        $this->assertEquals('cust_id_123', $customer->getCustomerId());
        $this->assertEquals('123456', $customer->getVerificationCode());
        $this->assertEquals($now->modify('+10min')->format('Y-m-d H:i:s'), $customer->getVerificationCodeExpiresAt()->format('Y-m-d H:i:s'));
    }

    public function testContratsCollection()
    {
        $customer = new Customer();
        $contrat = new Contrats();

        $this->assertCount(0, $customer->getContrats());
        $customer->addContrat($contrat);
        $this->assertCount(1, $customer->getContrats());
        $this->assertSame($customer, $contrat->getCustomer());

        // No removeContrat method in entity
        // $customer->removeContrat($contrat);
        // $this->assertCount(0, $customer->getContrats());
        // $this->assertNull($contrat->getCustomer());
    }

    public function testDevisCollection()
    {
        $customer = new Customer();
        $devis = new Devis();

        $this->assertCount(0, $customer->getDevis());
        $customer->addDevi($devis); // Use addDevi
        $this->assertCount(1, $customer->getDevis());
        $this->assertSame($customer, $devis->getCustomer());

        // No removeDevi method in entity
        // $customer->removeDevi($devis);
        // $this->assertCount(0, $customer->getDevis());
        // $this->assertNull($devis->getCustomer());
    }

    public function testCustomerAddressesCollection()
    {
        $customer = new Customer();
        $address = new CustomerAddress();

        $this->assertCount(0, $customer->getCustomerAddresses());
        $customer->addCustomerAddress($address);
        $this->assertCount(1, $customer->getCustomerAddresses());
        $this->assertSame($customer, $address->getCustomer());

        // No removeCustomerAddress method in entity
        // $customer->removeCustomerAddress($address);
        // $this->assertCount(0, $customer->getCustomerAddresses());
        // $this->assertNull($address->getCustomer());
    }

    public function testOrderSessionsCollection()
    {
        $customer = new Customer();
        $orderSession = new OrderSession();

        $this->assertCount(0, $customer->getOrderSessions());
        $customer->addOrderSession($orderSession);
        $this->assertCount(1, $customer->getOrderSessions());
        $this->assertSame($customer, $orderSession->getCustomer());

        $customer->removeOrderSession($orderSession);
        $this->assertCount(0, $customer->getOrderSessions());
        $this->assertNull($orderSession->getCustomer());
    }

    public function testCustomerTrackingsCollection()
    {
        $customer = new Customer();
        $tracking = new CustomerTracking();

        $this->assertCount(0, $customer->getCustomerTrackings());
        $customer->addCustomerTracking($tracking);
        $this->assertCount(1, $customer->getCustomerTrackings());
        $this->assertSame($customer, $tracking->getCustomer());

        $customer->removeCustomerTracking($tracking);
        $this->assertCount(0, $customer->getCustomerTrackings());
        $this->assertNull($tracking->getCustomer());
    }
}
