<?php

namespace SugarCalendarBookings\Availability;

use DateTimeZone;
use SugarCalendarBookings\Employees\EmployeeModel;

/**
 * Factory for working schedule rules.
 *
 * @since 1.0.0
 */
class WorkingScheduleRuleFactory {

	/**
	 * Create a rule from array data.
	 *
	 * @since 1.0.0
	 *
	 * @param array         $data      Rule data (must include 'type').
	 * @param DateTimeZone  $time_zone Time zone.
	 * @param EmployeeModel $employee  Employee model.
	 * @param int           $priority  Priority.
	 *
	 * @return AbstractWorkingScheduleRule|null
	 */
	public static function from_array( $data, $time_zone, $employee, $priority ) {

		if ( empty( $data['type'] ) ) {
			return null;
		}

		$rule = null;

		switch ( $data['type'] ) {
			case 'weekday':
				$rule = WorkingScheduleWeekdayRule::from_array( $data, $time_zone, $employee, $priority );
				break;

			case 'date_range':
				$rule = WorkingScheduleDateRangeRule::from_array( $data, $time_zone, $employee, $priority );
				break;
		}

		return $rule;
	}
}
