<?php

namespace Lc\ShopBundle\Services ;

use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\TaxRateInterface;

class TaxRateUtils
{
        protected $em ;
        protected $merchantUtils ;

        public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
        {
                $this->em = $em ;
                $this->merchantUtils = $merchantUtils ;
        }

        public function getTaxRatesList()
        {
                $taxRatesList =array();
                $taxRates = $this->em->getRepository(TaxRateInterface::class)->findAll();
                foreach ($taxRates as $taxRate){
                        $taxRatesList[$taxRate->getId()]['title'] = $taxRate->getTitle();
                        $taxRatesList[$taxRate->getId()]['value'] = $taxRate->getValue();
                }

                $taxRatesList['default']['title'] = $this->merchantUtils->getMerchantCurrentTaxRate()->getTitle();
                $taxRatesList['default']['value'] = $this->merchantUtils->getMerchantCurrentTaxRate()->getValue();
                return $taxRatesList;
        }
}