<?php

namespace App\Classes\Modules\Bookings\DataTransferObjects;

use App\Classes\General\Interfaces\DataTransferObject;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyServiceConfigurationsObject;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;

class CalculationObject implements DataTransferObject
{

    /** @var CurrencyConversionObject */
    private $conversionObject;

    /** @var CompanyServiceConfigurationsObject */
    private $configurations;

    /**
     * CalculationObject constructor.
     * @param CurrencyConversionObject $conversionObject
     * @param CompanyServiceConfigurationsObject $configurations
     */
    public function __construct(CurrencyConversionObject $conversionObject, CompanyServiceConfigurationsObject $configurations)
    {
        $this->conversionObject = $conversionObject;
        $this->configurations = $configurations;
    }

    /**
     * @return CurrencyConversionObject
     */
    public function getConversionObject(): CurrencyConversionObject
    {
        return $this->conversionObject;
    }


    /**
     * @return CompanyServiceConfigurationsObject
     */
    public function getConfigurations(): CompanyServiceConfigurationsObject
    {
        return $this->configurations;
    }

    public function getConvertibleTotal(){
        return $this->getConversionObject()->getType() === 1 ? $this->getConversionObject()->getAmount() : $this->getConversionTotal();
    }

    /**
     * @return float
     */
    public function getConversionTotal(): float {
        $rate = $this->getConversionObject()->getType() === 1 ? (1/$this->getConfigurations()->getRate()) : $this->getConfigurations()->getRate();
        return $this->getConversionObject()->getAmount() * $rate;
    }

    /**
     * @return float
     */
    public function getLocalTotal(){
        return $this->getConversionObject()->getType() === 1 ?  $this->getConversionTotal() : $this->getConversionObject()->getAmount();
    }

    /**
     * @return float
     */
    public function getForeignTotal(){
        return $this->getConversionObject()->getType() === 1 ?   $this->getConversionObject()->getAmount() : $this->getConversionTotal();
    }

    /**
     * @return float
     */
    public function getServiceCharge(): float {
        return ($this->getLocalTotal()/100) * $this->getConfigurations()->getServiceCharge() < $this->getConfigurations()->getMinimumCharge() ? $this->getConfigurations()->getMinimumCharge() : ($this->getLocalTotal()/100) * $this->getConfigurations()->getServiceCharge();
    }

    public function getSubTotal(): float {
        return $this->getLocalTotal() + $this->getServiceCharge();
    }

    /**
     * @return float
     */
    public function getTax(): float {
        return ($this->getSubTotal()/100) * $this->getConfigurations()->getTax();
    }

    public function getTotal(): float {
        return $this->getSubTotal() + $this->getTax();
    }


}