<?php

namespace Tests\Unit;

use Tests\TestCase;

class CalculationTest extends TestCase
{
    /**
     * Test product price and discount calculations.
     */
    public function test_product_price_and_discount_calculation(): void
    {
        $price = 100.00;
        $discountPercent = 15; // 15% discount
        $discountAmount = $price * ($discountPercent / 100);
        $finalPrice = $price - $discountAmount;

        $this->assertEquals(15.00, $discountAmount);
        $this->assertEquals(85.00, $finalPrice);
    }

    /**
     * Test tax calculations.
     */
    public function test_tax_calculation(): void
    {
        $subtotal = 85.00;
        $taxRate = 10; // 10% VAT
        $taxAmount = $subtotal * ($taxRate / 100);
        $totalWithTax = $subtotal + $taxAmount;

        $this->assertEquals(8.50, $taxAmount);
        $this->assertEquals(93.50, $totalWithTax);
    }

    /**
     * Test fixed shipping-fee calculations.
     */
    public function test_fixed_shipping_fee_calculation(): void
    {
        $subtotal = 85.00;
        $shippingFee = 2.00; // Fixed Delivery fee
        $totalWithShipping = $subtotal + $shippingFee;

        $this->assertEquals(87.00, $totalWithShipping);
    }

    /**
     * Test order total calculation logic.
     */
    public function test_order_total_calculation(): void
    {
        $subtotal = 100.00;
        $discount = 15.00;
        $tax = 8.50;
        $shippingFee = 2.00;

        $total = $subtotal - $discount + $tax + $shippingFee;

        $this->assertEquals(95.50, $total);
    }

    /**
     * Test payment amount validation.
     */
    public function test_payment_amount_validation(): void
    {
        $orderTotal = 95.50;
        
        $validPaymentAmount = 95.50;
        $invalidPaymentAmount = 90.00;

        $this->assertTrue(abs($orderTotal - $validPaymentAmount) < 0.001);
        $this->assertFalse(abs($orderTotal - $invalidPaymentAmount) < 0.001);
    }
}
