<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace ArtabanMarketplace\Loop;

use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use ArtabanMarketplaceColissimo\ArtabanMarketplaceColissimo;

/**
 * Description of AmpPostageEstimationLoop
 *
 * @author LENGY
 */
class AmpCartWeightPostageEstimationLoop extends BaseLoop implements PropelSearchLoopInterface {

    /**
     * @inheritDoc
     */
    protected function getArgDefinitions() {
        return new ArgumentCollection(
                Argument::createIntTypeArgument('weight')
        );
    }

    public function parseResults(LoopResult $loopResult) {
        
        $country = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
        
        $colissimo = new ArtabanMarketplaceColissimo();
        $area = $colissimo->getAreaForCountry($country);
        $areaId = $area->getId();
        $postageAmount = $colissimo->getPostageAmountWeight($areaId,$this->getWeight());

        $loopResultRow = new LoopResultRow();
        $loopResultRow->set("POSTAGE_AMOUNT", $postageAmount);

        $loopResult->addRow($loopResultRow);


        return $loopResult;
    }

    /**
     * @inheritdoc
     */
    public function buildModelCriteria() {
        return null;
    }

    /**
     * Return the event dispatcher,
     *
     * @return \Symfony\Component\EventDispatcher\EventDispatcher
     */
    public function getDispatcher() {
        return $this->dispatcher;
    }

}
