<?php

namespace App\Utils\InvoiceDueDate;

class Customer extends \App\Utils\InvoiceDueDate\GeneralAbstract
{

	/**
	 *
	 * {@inheritDoc}
	 * @see \App\Utils\InvoiceDueDate\GeneralAbstract::getEntityPreferenceObject()
	 */
	protected function getEntityPreferenceObject()
	{
		return \App\EntityPreference\Customer::getInstance($this->idEntity);
	}

	/**
	 *
	 * {@inheritDoc}
	 * @see \App\Utils\InvoiceDueDate\GeneralAbstract::getDefaultProfile()
	 */
	protected function getDefaultProfile()
	{

		// if no profile set - return null
		$defaultProfileDays = \App\Config\InvoiceDueDates::getInstance()->get('customer');
		if (!is_numeric($defaultProfileDays)) {
			return null;
		}

		// create a profile object with configured 'days'
		$profile = new \App\Utils\InvoiceDueDate\Profile();
		$profElem = new \App\Utils\InvoiceDueDate\Element();
		$profElem->setType('days')->setServiceCodes([''])->setOffset($defaultProfileDays);
		$profile->addElement($profElem);
		return $profile;

	}

}
