<commit_before><?php namespace Rtbs\ApiHelper;

use Rtbs\ApiHelper\Exceptions\ModelNotFoundException;
use Rtbs\ApiHelper\Models\Booking;
use Rtbs\ApiHelper\Models\Category;
use Rtbs\ApiHelper\Models\Pickup;
use Rtbs\ApiHelper\Models\Session;
use Rtbs\ApiHelper\Models\Supplier;
use Rtbs\ApiHelper\Models\Tour;

class BookingServiceImpl implements BookingService {
    private $api_client;
    private $credentials;

    /**
     * BookingServiceImpl constructor.
     * @param array $credentials
     */
    public function __construct($credentials) {
        $this->credentials = $credentials;
    }

    /**
     * @return Category[]
     */
    public function get_categories() {
        $categories = array();

        $raw_categories = $this->get_api_client()->api_categories();

        foreach($raw_categories as $raw_category) {
            $categories[] = Category::fromRaw($raw_category);
        }


        return $categories;
    }

    /**
     * @param $supplier_key
     * @param $tour_keys
     * @param $date
     * @return array
     */
    public function get_sessions_and_advance_dates($supplier_key, $tour_keys, $date) {
        $sessions_and_advance_dates = array(
            'sessions' => array(),
            'advance_dates' => array(),
        );

        $response = $this->get_api_client()->api_sessions($supplier_key, $tour_keys, $date);

        foreach($response->sessions as $raw_session) {
            $sessions_and_advance_dates['sessions'][] = Session::from_raw($raw_session);
        }

        $sessions_and_advance_dates['advance_dates'] = $response->advance_dates;

        return $sessions_and_advance_dates;
    }

    /**
     * @return Supplier[]
     */
    public function get_suppliers() {
        $suppliers = array();

        $raw_suppliers = $this->get_api_client()->api_suppliers();

        foreach($raw_suppliers as $raw_supplier) {
            $suppliers[] = Supplier::fromRaw($raw_supplier);
        }


        return $suppliers;
    }

    /**
     * @param $tour_key
     * @return Pickup[]
     */
    public function get_pickups($tour_key) {
        $pickups = array();

        $raw_pickups = $this->get_api_client()->api_pickups($tour_key);

        foreach($raw_pickups as $raw_pickup) {
            $pickups[] = Pickup::from_raw($raw_pickup);
        }

        return $pickups;
    }

    /**
     * @param $tour_keys
     * @return Tour[]
     */
    public function get_tours($tour_keys) {
        $tours = array();

        $raw_tours = $this->get_api_client()->api_tours($tour_keys);

        foreach($raw_tours as $raw_tour) {
            $tours[] = Tour::from_raw($raw_tour);
        }


        return $tours;
    }

    /**
     *
     * @param string $supplier_key
     * @return Supplier
     * @throws ModelNotFoundException
     */
    public function get_supplier($supplier_key) {
        $raw_supplier = $this->get_api_client()->api_supplier($supplier_key);

        if($raw_supplier == null) {
            throw new ModelNotFoundException();
        }

        return Supplier::fromRaw($raw_supplier);
    }


    private function get_api_client() {
        if($this->api_client == null) {
            $this->api_client = new APIClient($this->credentials);
        }

        return $this->api_client;
    }


    /**
     * @param $booking Booking
     * @return string url | Booking
     */
    public function make_booking(Booking $booking) {
        $response = $this->get_api_client()->api_booking($booking);

        if(isset($response->url)) {<commit_msg>update error message for Expose to API<commit_after><?php namespace Rtbs\ApiHelper;

use Rtbs\ApiHelper\Exceptions\ModelNotFoundException;
use Rtbs\ApiHelper\Models\Booking;
use Rtbs\ApiHelper\Models\Category;
use Rtbs\ApiHelper\Models\Pickup;
use Rtbs\ApiHelper\Models\Session;
use Rtbs\ApiHelper\Models\Supplier;
use Rtbs\ApiHelper\Models\Tour;

class BookingServiceImpl implements BookingService {
    private $api_client;
    private $credentials;

    /**
     * BookingServiceImpl constructor.
     * @param array $credentials
     */
    public function __construct($credentials) {
        $this->credentials = $credentials;
    }

    /**
     * @return Category[]
     */
    public function get_categories() {
        $categories = array();

        $raw_categories = $this->get_api_client()->api_categories();

        foreach($raw_categories as $raw_category) {
            $categories[] = Category::fromRaw($raw_category);
        }


        return $categories;
    }

    /**
     * @param $supplier_key
     * @param $tour_keys
     * @param $date
     * @return array
     */
    public function get_sessions_and_advance_dates($supplier_key, $tour_keys, $date) {
        $sessions_and_advance_dates = array(
            'sessions' => array(),
            'advance_dates' => array(),
        );

        $response = $this->get_api_client()->api_sessions($supplier_key, $tour_keys, $date);

        foreach($response->sessions as $raw_session) {
            $sessions_and_advance_dates['sessions'][] = Session::from_raw($raw_session);
        }

        $sessions_and_advance_dates['advance_dates'] = $response->advance_dates;

        return $sessions_and_advance_dates;
    }

    /**
     * @return Supplier[]
     */
    public function get_suppliers() {
        $suppliers = array();

        $raw_suppliers = $this->get_api_client()->api_suppliers();

        foreach($raw_suppliers as $raw_supplier) {
            $suppliers[] = Supplier::fromRaw($raw_supplier);
        }


        return $suppliers;
    }

    /**
     * @param $tour_key
     * @return Pickup[]
     */
    public function get_pickups($tour_key) {
        $pickups = array();

        $raw_pickups = $this->get_api_client()->api_pickups($tour_key);

        foreach($raw_pickups as $raw_pickup) {
            $pickups[] = Pickup::from_raw($raw_pickup);
        }

        return $pickups;
    }

    /**
     * @param $tour_keys
     * @return Tour[]
     */
    public function get_tours($tour_keys) {
        $tours = array();

        $raw_tours = $this->get_api_client()->api_tours($tour_keys);

        foreach($raw_tours as $raw_tour) {
            $tours[] = Tour::from_raw($raw_tour);
        }


        return $tours;
    }

    /**
     *
     * @param string $supplier_key
     * @return Supplier
     * @throws ModelNotFoundException
     */
    public function get_supplier($supplier_key) {
        $raw_supplier = $this->get_api_client()->api_supplier($supplier_key);

        if($raw_supplier == null) {
            throw new ModelNotFoundException('Supplier Not Found, check Expose to API setting in RTBS');
        }

        return Supplier::fromRaw($raw_supplier);
    }


    private function get_api_client() {
        if($this->api_client == null) {
            $this->api_client = new APIClient($this->credentials);
        }

        return $this->api_client;
    }


    /**
     * @param $booking Booking
     * @return string url | Booking
     */
    public function make_booking(Booking $booking) {
        $response = $this->get_api_client()->api_booking($booking);

        if(isset($response->url)) {
{'fraction_non_alphanumeric': 0.13099888392857142, 'fraction_numerical': 0.0, 'mean_word_length': 2.524582104228122, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6407707', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2216, 'n_words': 371}