<?php

namespace App\Tests\Entity;

use App\Entity\Revendeur;
use App\Entity\User;
use PHPUnit\Framework\TestCase;

class RevendeurTest extends TestCase
{
    private function createRevendeur(): Revendeur
    {
        $user = new User();
        $user->setEmail('r@test.com');
        $user->setFirstName('Jane');
        $user->setLastName('Smith');
        $user->setPassword('h');

        return new Revendeur($user, 'SC-0001');
    }

    public function testConstructor(): void
    {
        $rev = $this->createRevendeur();
        $this->assertNull($rev->getId());
        $this->assertSame('SC-0001', $rev->getCodeRevendeur());
        $this->assertSame('Jane', $rev->getUser()->getFirstName());
        $this->assertInstanceOf(\DateTimeImmutable::class, $rev->getCreatedAt());
        $this->assertTrue($rev->isActive());
    }

    public function testRaisonSociale(): void
    {
        $rev = $this->createRevendeur();
        $this->assertNull($rev->getRaisonSociale());
        $rev->setRaisonSociale('SARL Test');
        $this->assertSame('SARL Test', $rev->getRaisonSociale());
    }

    public function testSiret(): void
    {
        $rev = $this->createRevendeur();
        $rev->setSiret('12345678901234');
        $this->assertSame('12345678901234', $rev->getSiret());
    }

    public function testAddress(): void
    {
        $rev = $this->createRevendeur();
        $rev->setAddress('1 rue Test');
        $rev->setZipCode('02100');
        $rev->setCity('Saint-Quentin');
        $this->assertSame('1 rue Test', $rev->getAddress());
        $this->assertSame('02100', $rev->getZipCode());
        $this->assertSame('Saint-Quentin', $rev->getCity());
    }

    public function testContact(): void
    {
        $rev = $this->createRevendeur();
        $rev->setEmail('contact@test.fr');
        $rev->setPhone('0612345678');
        $this->assertSame('contact@test.fr', $rev->getEmail());
        $this->assertSame('0612345678', $rev->getPhone());
    }

    public function testStripeConnect(): void
    {
        $rev = $this->createRevendeur();
        $this->assertNull($rev->getStripeConnectId());
        $this->assertFalse($rev->isUseStripe());

        $rev->setStripeConnectId('acct_xxx');
        $rev->setIsUseStripe(true);
        $this->assertSame('acct_xxx', $rev->getStripeConnectId());
        $this->assertTrue($rev->isUseStripe());
    }

    public function testStripeConnectState(): void
    {
        $rev = $this->createRevendeur();
        $this->assertSame('not_started', $rev->getStripeConnectState());
        $this->assertNull($rev->getStripeConnectStatePayment());
        $this->assertNull($rev->getStripeConnectStatePayout());

        $rev->setStripeConnectState('active');
        $rev->setStripeConnectStatePayment('enabled');
        $rev->setStripeConnectStatePayout('enabled');
        $this->assertSame('active', $rev->getStripeConnectState());
        $this->assertSame('enabled', $rev->getStripeConnectStatePayment());
        $this->assertSame('enabled', $rev->getStripeConnectStatePayout());
    }

    public function testContratPdf(): void
    {
        $rev = $this->createRevendeur();
        $this->assertNull($rev->getContratResellerPdfUnsigned());
        $this->assertNull($rev->getContratResellerPdfSigned());
        $this->assertNull($rev->getContratResellerPdfAudit());
        $this->assertNull($rev->getContratSubmitterId());

        $rev->setContratResellerPdfUnsigned('/path/unsigned.pdf');
        $rev->setContratResellerPdfSigned('/path/signed.pdf');
        $rev->setContratResellerPdfAudit('/path/audit.pdf');
        $rev->setContratSubmitterId(42);
        $this->assertSame('/path/unsigned.pdf', $rev->getContratResellerPdfUnsigned());
        $this->assertSame('/path/signed.pdf', $rev->getContratResellerPdfSigned());
        $this->assertSame('/path/audit.pdf', $rev->getContratResellerPdfAudit());
        $this->assertSame(42, $rev->getContratSubmitterId());
    }

    public function testActive(): void
    {
        $rev = $this->createRevendeur();
        $rev->setIsActive(false);
        $this->assertFalse($rev->isActive());
    }

    public function testUpdatedAt(): void
    {
        $rev = $this->createRevendeur();
        $this->assertNull($rev->getUpdatedAt());
        $date = new \DateTimeImmutable();
        $rev->setUpdatedAt($date);
        $this->assertSame($date, $rev->getUpdatedAt());
    }
}
