<?php

namespace App\Tests\Entity;

use App\Entity\Customer;
use App\Entity\CustomerContact;
use App\Entity\User;
use PHPUnit\Framework\TestCase;

class CustomerContactTest extends TestCase
{
    private function createCustomer(): Customer
    {
        $user = new User();
        $user->setEmail('c@t.com');
        $user->setFirstName('C');
        $user->setLastName('T');
        $user->setPassword('h');

        return new Customer($user);
    }

    public function testConstructor(): void
    {
        $customer = $this->createCustomer();
        $contact = new CustomerContact($customer, 'Jean', 'Dupont');

        $this->assertNull($contact->getId());
        $this->assertSame($customer, $contact->getCustomer());
        $this->assertSame('Jean', $contact->getFirstName());
        $this->assertSame('Dupont', $contact->getLastName());
        $this->assertSame('Jean Dupont', $contact->getFullName());
        $this->assertNull($contact->getEmail());
        $this->assertNull($contact->getPhone());
        $this->assertNull($contact->getRole());
        $this->assertFalse($contact->isBillingEmail());
        $this->assertInstanceOf(\DateTimeImmutable::class, $contact->getCreatedAt());
        $this->assertNull($contact->getUpdatedAt());
    }

    public function testSetters(): void
    {
        $contact = new CustomerContact($this->createCustomer(), 'A', 'B');

        $contact->setFirstName('Marie');
        $this->assertSame('Marie', $contact->getFirstName());

        $contact->setLastName('Martin');
        $this->assertSame('Martin', $contact->getLastName());
        $this->assertSame('Marie Martin', $contact->getFullName());

        $contact->setEmail('marie@entreprise.fr');
        $this->assertSame('marie@entreprise.fr', $contact->getEmail());

        $contact->setPhone('0612345678');
        $this->assertSame('0612345678', $contact->getPhone());

        $contact->setRole('Comptable');
        $this->assertSame('Comptable', $contact->getRole());

        $contact->setIsBillingEmail(true);
        $this->assertTrue($contact->isBillingEmail());

        $now = new \DateTimeImmutable();
        $contact->setUpdatedAt($now);
        $this->assertSame($now, $contact->getUpdatedAt());
    }
}
