<?php

namespace AcceptBlue\Level3;

class WCAmountDetailsFields
{
    private \WC_Order $order;
    private float $tax = 0;
    private float $taxPercent = 0;
    public function __construct(\WC_Order $order)
    {
        $this->order = $order;
        $this->calculateTax();
    }

    private function calculateTax(): void
    {
        $this->tax = (float) $this->order->get_total_tax();
        $this->taxPercent = (float) $this->order->get_total_tax() / (float) $this->order->get_total() * 100;
    }

    public function getTax(): float
    {
        return $this->tax;
    }

    public function getTaxPercent(): float
    {
        return $this->taxPercent;
    }

    public function getShippingTotal(): float
    {
        return (float) $this->order->get_shipping_total();
    }

    public function getDiscountTotal(): float {
        return (float) $this->order->get_discount_total();
    }

    public function getAllFields(): object
    {
        return (object) array(
            'tax' => (float) $this->getTax(),
            'tax_percent' => (float) $this->getTaxPercent(),
            'shipping' => (float) $this->order->get_shipping_total(),
            'tip' => 0,
            'discount' => (float) $this->order->get_discount_total(),
        );
    }
}