<?php
namespace Tests\Unit\Domain\Basket;

use PHPUnit\Framework\TestCase;
use Domain\Basket\BasketCalculator;

class BasketCalculatorTest extends TestCase
{
    public function testSummaryWpCalculatesTotal(): void
    {
        $basket = [
            ['wp' => 2, 'quantity' => 3],
            ['wp' => 5, 'quantity' => 1],
        ];

        $this->assertSame(11, BasketCalculator::summaryWp($basket));
    }

    public function testSummaryWpReturnsZeroForEmptyBasket(): void
    {
        $this->assertSame(0, BasketCalculator::summaryWp([]));
        $this->assertSame(0, BasketCalculator::summaryWp(null));
    }

    public function testCountProductsSumsQuantities(): void
    {
        $basket = [
            ['quantity' => 2],
            ['quantity' => 3],
            ['quantity' => 1],
        ];

        $this->assertSame(6, BasketCalculator::countProducts($basket));
    }

    public function testCountProductsReturnsZeroForEmptyBasket(): void
    {
        $this->assertSame(0, BasketCalculator::countProducts([]));
        $this->assertSame(0, BasketCalculator::countProducts(null));
    }

    public function testCountProductsTextSingular(): void
    {
        $this->assertSame('1 produkt', BasketCalculator::countProductsText(1));
    }

    public function testCountProductsTextPlural2to4(): void
    {
        $this->assertSame('2 produkty', BasketCalculator::countProductsText(2));
        $this->assertSame('3 produkty', BasketCalculator::countProductsText(3));
        $this->assertSame('4 produkty', BasketCalculator::countProductsText(4));
    }

    public function testCountProductsTextPlural5Plus(): void
    {
        $this->assertSame('0 produktów', BasketCalculator::countProductsText(0));
        $this->assertSame('5 produktów', BasketCalculator::countProductsText(5));
        $this->assertSame('12 produktów', BasketCalculator::countProductsText(12));
        $this->assertSame('100 produktów', BasketCalculator::countProductsText(100));
    }

    public function testCountProductsTextCastsToInt(): void
    {
        $this->assertSame('3 produkty', BasketCalculator::countProductsText('3'));
        $this->assertSame('0 produktów', BasketCalculator::countProductsText('abc'));
    }

    public function testCheckProductQuantityInStockReturnsFalseOnNullBasket(): void
    {
        $this->assertFalse(BasketCalculator::checkProductQuantityInStock(null));
    }

    public function testCheckProductQuantityInStockReturnsFalseOnEmptyBasket(): void
    {
        $this->assertFalse(BasketCalculator::checkProductQuantityInStock([]));
    }

    public function testValidateBasketReturnsEmptyArrayOnNull(): void
    {
        $this->assertSame([], BasketCalculator::validateBasket(null));
    }

    public function testValidateBasketReturnsBasketArrayAsIs(): void
    {
        $basket = [['product-id' => 1, 'quantity' => 2]];
        $this->assertSame($basket, BasketCalculator::validateBasket($basket));
    }
}
