<?php
/**
 * Booking Calendar
 *
 * @package Booktics
 */

namespace Booktics\Add_To_Calendar;

use Booktics\Abstracts\Base_Rest_Controller;
use Booktics\Utils\Singleton;

class Add_To_Calendar_Controller extends Base_Rest_Controller {
    use Singleton;

    /**
     * Store api namespace
     *
     * @var string
     */
    protected $namespace = 'booktics/v1';

    /**
     * Store rest base
     *
     * @var string
     */
    protected $rest_base = 'add-to-calendar';

    /**
     * Register rest routes
     *
     * @return  void
     */
    public function register_routes() : void {
        register_rest_route(
            $this->namespace, $this->rest_base, array(
                array(
                    'methods'             => \WP_REST_Server::READABLE,
                    'callback'            => array( $this, 'get_add_to_calendar_links' ),
                    'permission_callback' => '__return_true',
                ),
            )
        );
    }

    /**
     * Get calendar data
     *
     * @param \WP_REST_Request $request
     * @return \WP_REST_Response
     */
    public function get_add_to_calendar_links( $request ) {
        $calendars = array();
        $calendars = apply_filters( 'booktics_booking_calendar_urls', $calendars, $request );

        $data = array(
            'calendars' => $calendars,
        );

        return $this->response( $data , __( 'Add to Calendar links added successfully', 'booktics' ));
    }
}
