<?php

namespace App\Classes\Modules\ServiceTypes\DataTransferObjects;


use App\Classes\General\Interfaces\DataTransferObject;
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceCurrenciesConfigurations;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Models\SegmentConstant;
use Illuminate\Support\Collection;

class CustomConfigurationsObject implements DataTransferObject
{


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

    /** @var SegmentConstant */
    private $customOptions;

    /**
     * CustomConfigurationsObject constructor.
     * @param SegmentConstant $configurations
     * @param SegmentConstant $customOptions
     */
    public function __construct(SegmentConstant $configurations, SegmentConstant $customOptions)
    {
        $this->configurations = $configurations;
        $this->customOptions = $customOptions;
    }

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

    /**
     * @return SegmentConstant
     */
    public function getCustomOptions(): SegmentConstant
    {
        return $this->customOptions;
    }


    /**
     * @param string $name
     * @return mixed
     */
    public function getConfigurationValue(string $name) {
        return property_exists($this->getCustomOptions()->detail, $name) ?
            $this->getCustomOptions()->detail->$name: $this->configurations->detail->$name;
    }


    /**
     * @return mixed
     */
    public function calculateServiceCharge(){
        return ($this->getConfigurationValue('service_charge')->value * 0.01) > $this->getConfigurationValue('minimum_charge')->value ?
            $this->getConfigurationValue('service_charge')->value : $this->getConfigurationValue('minimum_charge')->value;
    }

    /**
     * @return float
     */
    public function calculateTax(){
        return $this->getConfigurationValue('tax')->value * 0.01;
    }

}