<?php

namespace App\Tests\Entity;

use App\Entity\Facture;
use App\Entity\FactureLine;
use App\Entity\OrderNumber;
use PHPUnit\Framework\TestCase;

class FactureLineTest extends TestCase
{
    private function createFacture(): Facture
    {
        $order = new OrderNumber('04/2026-88001');

        return new Facture($order, 'test-secret');
    }

    public function testConstructorMinimalArgs(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Hébergement web');

        $this->assertNull($line->getId());
        $this->assertSame($facture, $line->getFacture());
        $this->assertSame('Hébergement web', $line->getTitle());
        $this->assertSame('0.00', $line->getPriceHt());
        $this->assertSame(0, $line->getPos());
        $this->assertNull($line->getDescription());
        $this->assertNull($line->getType());
        $this->assertNull($line->getServiceId());
    }

    public function testConstructorWithAllArgs(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Nom de domaine .fr', '12.00', 2);

        $this->assertSame('Nom de domaine .fr', $line->getTitle());
        $this->assertSame('12.00', $line->getPriceHt());
        $this->assertSame(2, $line->getPos());
    }

    public function testTitle(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Initial');

        $line->setTitle('Nouveau titre');
        $this->assertSame('Nouveau titre', $line->getTitle());
    }

    public function testPriceHt(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Test');

        $line->setPriceHt('249.99');
        $this->assertSame('249.99', $line->getPriceHt());
    }

    public function testPos(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Test');

        $this->assertSame(0, $line->getPos());
        $line->setPos(5);
        $this->assertSame(5, $line->getPos());
    }

    public function testDescription(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Test');

        $this->assertNull($line->getDescription());
        $line->setDescription('Description détaillée du service.');
        $this->assertSame('Description détaillée du service.', $line->getDescription());
        $line->setDescription(null);
        $this->assertNull($line->getDescription());
    }

    public function testType(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Test');

        $this->assertNull($line->getType());
        $line->setType('hosting');
        $this->assertSame('hosting', $line->getType());
        $line->setType(null);
        $this->assertNull($line->getType());
    }

    public function testServiceId(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Test');

        $this->assertNull($line->getServiceId());
        $line->setServiceId(42);
        $this->assertSame(42, $line->getServiceId());
        $line->setServiceId(null);
        $this->assertNull($line->getServiceId());
    }

    public function testSettersReturnStatic(): void
    {
        $facture = $this->createFacture();
        $line = new FactureLine($facture, 'Test');

        $this->assertSame($line, $line->setTitle('T'));
        $this->assertSame($line, $line->setPriceHt('1.00'));
        $this->assertSame($line, $line->setPos(1));
        $this->assertSame($line, $line->setDescription('D'));
        $this->assertSame($line, $line->setType('type'));
        $this->assertSame($line, $line->setServiceId(1));
    }
}
