<?php 
/**
 * @package    Proxim
 * @author     Dominic Tanui <dominic@codeworldweb.com | https://codeworldweb.com>
 * @copyright  2020 Proxim
 * @version    1.0
 * @since      File available since Release 1.0
*/

namespace Proxim\Presenter\Deadline;

use Proxim\Presenter\AbstractLazyArray;
use Doctrine\Common\Annotations\AnnotationException;
use Proxim\Application;
use Proxim\Currency;
use Proxim\Preference\Deadline;
use Proxim\Util\ArrayUtils;

class DeadlineLazyArray extends AbstractLazyArray {
    /** @var Application */
    private $application;

    /** @var Deadline */
    private $deadline;

    /**
     * DeadlineArray constructor.
     *
     * @throws AnnotationException
     * @throws ReflectionException
     */
    public function __construct(Deadline $deadline)
    {
        $this->application = Application::getInstance();
        $this->deadline = $deadline;

        parent::__construct();
    }

    /**
     * @arrayAccess
     *
     * @return int
     */
    public function getId()
    {
        return (int) $this->deadline->id;
    }

    /**
     * @arrayAccess
     *
     * @return int
     */
    public function getAcademicLevel()
    {
        return (int) $this->deadline->academic_level_id;
    }

    /**
     * @arrayAccess
     *
     * @return int
     */
    public function getAcademicLevelTitle()
    {
        global $globals;
        $academicLevels = ArrayUtils::get($globals, 'academicLevels');
        $academicLevel = ArrayUtils::get($academicLevels, $this->deadline->academic_level_id);

        return (string) ArrayUtils::get($academicLevel, 'title');
    }

    /**
     * @arrayAccess
     *
     * @return string
     */
    public function getName()
    {
        return $this->deadline->name;
    }

    /**
     * @arrayAccess
     *
     * @return float
     */
    public function getPricePerPage()
    {
        $deadline = $this->deadline;
        $currency_id = Currency::getIdByIsoCode('USD');
        $currency = Currency::getCurrencyInstance( $currency_id );

        return array(
            'currency' => $currency->iso_code,
            'value' => toFixed($deadline->price_per_page),
            'amountFormatted' => formatPrice($deadline->price_per_page),
        );
    }

    /**
     * @arrayAccess
     *
     * @return int
     */
    public function getHrs()
    {
        return (int) $this->deadline->hrs_customer;
    }

    /**
     * @arrayAccess
     *
     * @return int
     */
    public function getHrsWriter()
    {
        return (int) $this->deadline->hrs_writer;
    }

    /**
     * @arrayAccess
     *
     * @return int
     */
    public function getMinPages()
    {
        return (int) $this->deadline->min_pages;
    }
}