<?php

class CronJobFactory
{

    const SYSTEMUPDATE = 'SystemUpdate';
    const CLEANUP = 'Cleanup';
    const SYSTEMSTATISTICS = 'SystemStatistics';
    const LDAP_IMPORT = 'LdapImport';
    const CALLPROTECTION = 'CallProtection';

    public static function getAllCronJobNames()
    {
        $allCronJobs = array(
            CronJobFactory::CLEANUP,
            CronJobFactory::LDAP_IMPORT,
            CronJobFactory::CALLPROTECTION
        );

        if (app()->params->applianceMode) {
            $allCronJobs[] = CronJobFactory::SYSTEMUPDATE;
            $allCronJobs[] = CronJobFactory::SYSTEMSTATISTICS;
        }
        return $allCronJobs;
    }

    public static function getCronJobInstance($cronJobName)
    {
        if ($cronJobName === CronJobFactory::SYSTEMUPDATE) {
            $cronJob = new SystemUpdateCronJob();
        } else if ($cronJobName === CronJobFactory::CLEANUP) {
            $cronJob = new CleanupCronJob();
        } else if ($cronJobName === CronJobFactory::SYSTEMSTATISTICS) {
            $cronJob = new SystemStatisticsCronJob();
        } else if ($cronJobName === CronJobFactory::LDAP_IMPORT) {
            $cronJob = new LdapImportCronJob();
        } else if ($cronJobName === CronJobFactory::CALLPROTECTION) {
            $cronJob = new CallProtectionCronJob();
        } else {
            throw new CHttpException(404, 'Invalid request. Object type does not exist.');
        }
        return $cronJob;
    }
}
