<?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 ArtabanMarketplaceColissimo\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 MaxWeight
 *
 * @author LENGY
 */
class MaxWeight extends BaseLoop implements PropelSearchLoopInterface {

    /**
     * @inheritDoc
     */
    protected function getArgDefinitions() {
        return new ArgumentCollection(
        );
    }

    public function parseResults(LoopResult $loopResult) {

        $prices = ArtabanMarketplaceColissimo::getPrices();
        
        $country = $this->container->get('thelia.taxEngine')->getDeliveryCountry();

        
        $colissimo = new ArtabanMarketplaceColissimo();
        
        $areaId = $colissimo->getAreaForCountry($country)->getId();
        
        $areaPrices = $prices[$areaId]["slices"];

        krsort($areaPrices);

        $maxWeight = key($areaPrices);

        $loopResultRow = new LoopResultRow();
        
        $loopResultRow->set("MAX_WEIGHT", $maxWeight);

        $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;
    }

}
