<?php

namespace Booktics\Appointment\Schedule;

use Booktics\Models\Service_Model;
use Booktics\Models\Team_Member_Model;

class Time_Slot_Strategy_Factory {
    /**
     * Factory method to get the appropriate time slot strategy based on available schedule entries.
     *
     * @param array $service_entries Array of service schedule entries.
     * @param array $team_entries Array of team member schedule entries.
     * @param array $default_entries Array of default schedule entries.
     * @param int $service_id
     * @return Time_Slot_Strategy The appropriate time slot strategy based on the combination of schedule entries.
     */
    public static function get_strategy(
        $service_id,
        $team_member_id
    ): Time_Slot_Strategy {
        $service_has_custom_schedule = false;
        $team_member_has_custom_availability = false;

        if ( isset( $service_id ) ) {
            $service = new Service_Model($service_id);
            $service_has_custom_schedule = $service->enable_custom_schedule;
        }

        if ( isset( $team_member_id ) ) {
            $team_member_has_custom_availability = ( new Team_Member_Model( $team_member_id ) )->enable_custom_availability ?? false;
        }

        if ( $team_member_has_custom_availability ) {
            return new Team_Member_Only_Strategy();
        }

        if ( $service_has_custom_schedule ) {
            return new Service_Only_Strategy(); 
        }

        return new Default_Only_Strategy();
    }
}
