<?php

namespace App\Tests\Entity;

use App\Entity\Advert;
use App\Entity\AdvertLine;
use App\Entity\OrderNumber;
use PHPUnit\Framework\TestCase;

class AdvertLineTest extends TestCase
{
    private Advert $advert;

    protected function setUp(): void
    {
        $orderNumber = new OrderNumber('04/2026-00001');
        $this->advert = $this->createStub(Advert::class);
    }

    public function testConstructorDefaults(): void
    {
        $line = new AdvertLine($this->advert, 'Service Web');

        $this->assertSame($this->advert, $line->getAdvert());
        $this->assertSame('Service 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());
        $this->assertNull($line->getId());
    }

    public function testConstructorWithAllParams(): void
    {
        $line = new AdvertLine($this->advert, 'Hébergement', '120.00', 3);

        $this->assertSame('Hébergement', $line->getTitle());
        $this->assertSame('120.00', $line->getPriceHt());
        $this->assertSame(3, $line->getPos());
    }

    public function testSetPos(): void
    {
        $line = new AdvertLine($this->advert, 'Test');
        $result = $line->setPos(5);

        $this->assertSame(5, $line->getPos());
        $this->assertSame($line, $result); // fluent interface
    }

    public function testSetTitle(): void
    {
        $line = new AdvertLine($this->advert, 'Initial');
        $result = $line->setTitle('Updated Title');

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

    public function testSetDescription(): void
    {
        $line = new AdvertLine($this->advert, 'Test');
        $result = $line->setDescription('Une description détaillée');

        $this->assertSame('Une description détaillée', $line->getDescription());
        $this->assertSame($line, $result);
    }

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

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

    public function testSetPriceHt(): void
    {
        $line = new AdvertLine($this->advert, 'Test');
        $result = $line->setPriceHt('250.50');

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

    public function testSetType(): void
    {
        $line = new AdvertLine($this->advert, 'Test');
        $result = $line->setType('hosting');

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

    public function testSetTypeNull(): void
    {
        $line = new AdvertLine($this->advert, 'Test');
        $line->setType('domain');
        $line->setType(null);

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

    public function testSetServiceId(): void
    {
        $line = new AdvertLine($this->advert, 'Test');
        $result = $line->setServiceId(42);

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

    public function testSetServiceIdNull(): void
    {
        $line = new AdvertLine($this->advert, 'Test');
        $line->setServiceId(99);
        $line->setServiceId(null);

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

    public function testFluentInterfaceChainingAllSetters(): void
    {
        $line = new AdvertLine($this->advert, 'Chained');
        $result = $line
            ->setPos(2)
            ->setTitle('New Title')
            ->setDescription('Desc')
            ->setPriceHt('99.99')
            ->setType('ndd')
            ->setServiceId(7);

        $this->assertSame(2, $line->getPos());
        $this->assertSame('New Title', $line->getTitle());
        $this->assertSame('Desc', $line->getDescription());
        $this->assertSame('99.99', $line->getPriceHt());
        $this->assertSame('ndd', $line->getType());
        $this->assertSame(7, $line->getServiceId());
        $this->assertSame($line, $result);
    }
}
