<?php
if ( ! defined( 'WPINC' ) ) {
    die;
}

use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
use Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema;

class Epaka_Extend_Checkout_Store_Endpoint{
    /**
     * Stores Rest Extending instance.
     *
     * @var ExtendSchema
     */
    private static $extend;

    /**
     * Plugin Identifier, unique to each plugin.
     *
     * @var string
     */
    const IDENTIFIER = 'epaka-pl';

    /**
     * Bootstraps the class and hooks required data.
     *
     * @param ExtendSchema $extend_rest_api An instance of the ExtendSchema class.
     *
     * @since 3.1.0
     */
    public static function init( ExtendSchema $extend_rest_api ) {
        self::$extend = $extend_rest_api;
        self::extend_store();
    }

    /**
     * Registers the actual data into each endpoint.
     */
    public static function extend_store() {

        // Register into `cart/items`
        self::$extend->register_endpoint_data(
            array(
                'endpoint'        => CheckoutSchema::IDENTIFIER,
                'namespace'       => self::IDENTIFIER,
                'schema_callback' => array( 'Epaka_Extend_Checkout_Store_Endpoint', 'extend_checkout_schema' ),
                'schema_type'       => ARRAY_A,
            )
        );
    }

    /**
     * Register subscription product schema into cart/items endpoint.
     *
     * @return array Registered schema.
     */
    public static function extend_checkout_schema() {
        return array(
            'epaka_deliver_point'    => array(
                'description' => __( 'Punkt odbioru', 'epaka-pl' ),
                'type'        => array( 'string', 'null' ),
                'context'     => array( 'view', 'edit' ),
                'readonly'    => true,
            ),
            'epaka_delivery_point_description'    => array(
                'description' => __( 'Punkt odbioru opis', 'epaka-pl' ),
                'type'        => array( 'string', 'null' ),
                'context'     => array( 'view', 'edit' ),
                'readonly'    => true,
            ),
        );
    }
}