<?php
	
	use Automattic\WooCommerce\Blocks\Package;
	use Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema;
	use Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema;
	use Automattic\WooCommerce\StoreApi\StoreApi;
	use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
	
	/**
	 * Pickup Date Extend Store API.
	 */
	class Korkmaz_Blocks_Extend_Store_Endpoint {
		/**
		 * Stores Rest Extending instance.
		 *
		 * @var ExtendSchema
		 */
		private static $extend;
		
		/**
		 * Plugin Identifier, unique to each plugin.
		 *
		 * @var string
		 */
		const IDENTIFIER = 'irem';
		
		/**
		 * Bootstraps the class and hooks required data.
		 */
		public static function init() {
			self::$extend = StoreApi::container()->get( ExtendSchema::class );
			self::extend_store();
		}
		
		/**
		 * Registers the actual data into each endpoint.
		 */
		public static function extend_store() {
			
			if ( is_callable( [ self::$extend, 'register_endpoint_data' ] ) ) {
				self::$extend->register_endpoint_data(
					[
						'endpoint'        => CheckoutSchema::IDENTIFIER,
						'namespace'       => self::IDENTIFIER,
						'schema_callback' => [ self::class, 'extend_checkout_schema' ],
						'schema_type'     => ARRAY_A,
					]
				);
			}
		}
		
		
		/**
		 * Checkout endpoint'ine eklemek istediğimiz alanları burada tanımlıyoruz.
		 *
		 * @return array
		 */
		public static function extend_checkout_schema() {
			return [

				'billing_satis_sozlesme' => [
					'description' => 'Mesafeli Satış Sözleşmesi metni',
					'type'        => 'string',
					'context'     => [ 'view', 'edit' ],
					'readonly'    => false,
					'arg_options' => [
						'validate_callback' => static function ( $value ) {
							return is_string( $value );
						},
					],
				],
				'billing_mesafeli_sozlesme' => [
					'description' => 'Ön Bilgilendirme Formu metni',
					'type'        => 'string',
					'context'     => [ 'view', 'edit' ],
					'readonly'    => false,
					'arg_options' => [
						'validate_callback' => static function ( $value ) {
							return is_string( $value );
						},
					],
				],
				'sozlesme_onay' => [
					'description' => 'Sözleşme onay durumu',
					'type'        => 'string',
					'context'     => [ 'view', 'edit' ],
					'readonly'    => false,
					'arg_options' => [
						'validate_callback' => static function ( $value ) {
							return in_array( (string) $value, [ '0', '1', 'true', 'false', 'yes', 'no', 'on', 'off' ], true );
						},
					],
				],
			];
		}
	}
