<?php

namespace Devurai\AcceptbluePaymentPro\Surcharge;

class SurchargeSettings
{
    private array $surcharge;
    public function __construct(array $surcharge = array())
    {
        $this->surcharge = $surcharge;
    }
    public function set_surcharge_amount(float $surchargeAmount): void
    {
        $this->surcharge['surcharge_amount'] = $surchargeAmount;
    }
    
    public function set_surcharge_type(string $surchargeType): void
    {
        if (!in_array($surchargeType, ['currency', 'percentage'], true)) {
            throw new \InvalidArgumentException("Invalid surcharge type. Allowed values are 'currency' or 'percentage'.");
        }
        $this->surcharge['surcharge_type'] = $surchargeType;
    }
    
    public function set_surcharge_tax(string $surchargeTax): void
    {
        if (!in_array($surchargeTax, ['none', 'taxable'], true)) {
            throw new \InvalidArgumentException("Invalid surcharge tax. Allowed values are 'none' or 'taxable'.");
        }
        $this->surcharge['surcharge_tax'] = $surchargeTax;
    }

    public function get_surcharge_amount(): float
    {
        return $this->surcharge['surcharge_amount'] ?? 0.0;
    }

    public function get_surcharge_type(): string
    {
        return $this->surcharge['surcharge_type'] ?? 'currency';
    }

    public function get_surcharge_tax(): string
    {
        return $this->surcharge['surcharge_tax'] ?? 'none';
    }

    public function is_surcharge_currency(): bool
    {
        $type = $this->get_surcharge_type();
        return $type === 'currency';
    }

    public function to_array(): array
    {
        return $this->surcharge;
    }
}