<?php

namespace App\Tests\Entity;

use App\Entity\Devis;
use App\Entity\DevisLine;
use PHPUnit\Framework\TestCase;

class DevisLineTest extends TestCase
{
    private Devis $devis;

    protected function setUp(): void
    {
        $this->devis = $this->createStub(Devis::class);
    }

    public function testConstructorDefaults(): void
    {
        $line = new DevisLine($this->devis, 'Création site');

        $this->assertSame($this->devis, $line->getDevis());
        $this->assertSame('Création site', $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());
        $this->assertNull($line->getId());
    }

    public function testConstructorWithAllParams(): void
    {
        $line = new DevisLine($this->devis, 'Maintenance', '75.00', 2);

        $this->assertSame('Maintenance', $line->getTitle());
        $this->assertSame('75.00', $line->getPriceHt());
        $this->assertSame(2, $line->getPos());
    }

    public function testSetPos(): void
    {
        $line = new DevisLine($this->devis, 'Test');
        $result = $line->setPos(4);

        $this->assertSame(4, $line->getPos());
        $this->assertSame($line, $result);
    }

    public function testSetTitle(): void
    {
        $line = new DevisLine($this->devis, 'Old Title');
        $result = $line->setTitle('New Title');

        $this->assertSame('New Title', $line->getTitle());
        $this->assertSame($line, $result);
    }

    public function testSetDescription(): void
    {
        $line = new DevisLine($this->devis, 'Test');
        $result = $line->setDescription('Description du service');

        $this->assertSame('Description du service', $line->getDescription());
        $this->assertSame($line, $result);
    }

    public function testSetDescriptionNull(): void
    {
        $line = new DevisLine($this->devis, 'Test');
        $line->setDescription('some desc');
        $line->setDescription(null);

        $this->assertNull($line->getDescription());
    }

    public function testSetPriceHt(): void
    {
        $line = new DevisLine($this->devis, 'Test');
        $result = $line->setPriceHt('199.99');

        $this->assertSame('199.99', $line->getPriceHt());
        $this->assertSame($line, $result);
    }

    public function testSetType(): void
    {
        $line = new DevisLine($this->devis, 'Test');
        $result = $line->setType('development');

        $this->assertSame('development', $line->getType());
        $this->assertSame($line, $result);
    }

    public function testSetTypeNull(): void
    {
        $line = new DevisLine($this->devis, 'Test');
        $line->setType('seo');
        $line->setType(null);

        $this->assertNull($line->getType());
    }

    public function testSetServiceId(): void
    {
        $line = new DevisLine($this->devis, 'Test');
        $result = $line->setServiceId(15);

        $this->assertSame(15, $line->getServiceId());
        $this->assertSame($line, $result);
    }

    public function testSetServiceIdNull(): void
    {
        $line = new DevisLine($this->devis, 'Test');
        $line->setServiceId(10);
        $line->setServiceId(null);

        $this->assertNull($line->getServiceId());
    }

    public function testFluentInterfaceChainingAllSetters(): void
    {
        $line = new DevisLine($this->devis, 'Initial');
        $result = $line
            ->setPos(1)
            ->setTitle('Final Title')
            ->setDescription('Desc')
            ->setPriceHt('500.00')
            ->setType('hosting')
            ->setServiceId(3);

        $this->assertSame(1, $line->getPos());
        $this->assertSame('Final Title', $line->getTitle());
        $this->assertSame('Desc', $line->getDescription());
        $this->assertSame('500.00', $line->getPriceHt());
        $this->assertSame('hosting', $line->getType());
        $this->assertSame(3, $line->getServiceId());
        $this->assertSame($line, $result);
    }
}
