<?php

namespace LivraisonParSecteurs\Loop;

use LivraisonParSecteurs\Model\LpsAreaScheduleQuery;
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\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use LivraisonParSecteurs\Model\LpsAreaQuery;

/**
 * Class AreaScheduleLoop
 * @package LivraisonParSecteurs\Loop
 */
class AreaScheduleLoop extends BaseLoop implements PropelSearchLoopInterface
{
    public $countable = false;
    public $timestampable = false;
    public $versionable = false;

    /**
     * @param LoopResult $loopResult
     *
     * @return LoopResult
     */
    public function parseResults(LoopResult $loopResult)
    {
        foreach ($loopResult->getResultDataCollection() as $lps_area_schedule) {

            $loopResultRow = new LoopResultRow($lps_area_schedule);
            $loopResultRow
                ->set("ID", $lps_area->getId())
                ->set("TITLE", $lps_area->getTitle())
                ->set("ACTIVE", $lps_area->getActive())
                ->set("PRICE", $lps_area->getPrice())
                ->set("DELIVERY_DAYS", "Lundi....")
            ;
            $loopResult->addRow($loopResultRow);
        }
        return $loopResult;
    }

    /**
     * @inheritdoc
     */
    protected function getArgDefinitions()
    {
        return new ArgumentCollection(
            Argument::createIntListTypeArgument('id_area')
        );
    }

    /**
     * @inheritdoc
     */
    public function buildModelCriteria()
    {
        $query = LpsAreaScheduleQuery::create();
        $query->filterByIdArea($this->getIdArea());

        return $query->orderByDay()->orderByBeginTime();
    }

}
