<?php
/**
 * Schema for the import file.
 *
 * @package Fast-Events/Schema
 * @since 1.0
 */

declare( strict_types=1 );

/**
 * Return the import schema.
 *
 * @since 1.0
 * @since 1.4 Added saas_fee, saas_user_id, sender_name and sender_email to query
 *
 * @return array
 */
function fast_events_schema_for_import(): array {
	return array(
		'$schema'     => 'http => //json-schema.org/draft-04/schema#',
		'title'       => 'Import schema for Fast Events',
		'description' => 'Import schema for the Fast Events WordPress plugin',
		'type'        => 'object',
		'properties'  => array(
			'home'   => array(
				'type'   => 'string',
				'format' => 'uri',
			),
			'events' => array(
				'description' => 'Array of events',
				'type'        => 'array',
				'minItems'    => 0,
				'items'       => array(
					'type'       => 'object',
					'properties' => array(
						'id'                          => array(
							'description' => 'Unique id of the event',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'start_date'                  => array(
							'type'      => 'string',
							'maxLength' => 19,
						),
						'end_date'                    => array(
							'type'      => 'string',
							'maxLength' => 19,
						),
						'event_name'                  => array(
							'type'      => 'string',
							'maxLength' => 50,
						),
						'event_date'                  => array(
							'type'      => 'string',
							'maxLength' => 19,
						),
						'event_date_format'           => array(
							'type'      => 'string',
							'maxLength' => 32,
						),
						'event_type'                  => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'stock'                       => array(
							'description' => 'Number of tickets on stock',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'saas_fee'                    => array(
							'description' => 'Seller fee',
							'type'        => array( 'string', 'null' ),
							'pattern'     => '^[0-9]{1,8}\.[0-9]{2}$',
						),
						'saas_user_id'                => array(
							'description' => 'The unique id of the user using Saas',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'sold'                        => array(
							'description' => 'Tickets sold',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'group_type'                  => array(
							'type' => 'string',
							'enum' => array( '0', '1', '2', '3' ),
						),
						'event_group'                 => array(
							'type'      => 'string',
							'maxLength' => 16,
						),
						'stock_link'                  => array(
							'description' => 'The unique id of the linked event',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'sender_name'                 => array(
							'type'      => array( 'string', 'null' ),
							'maxLength' => 100,
						),
						'sender_email'                => array(
							'type'      => array( 'string', 'null' ),
							'maxLength' => 100,
						),
						'email_bcc'                   => array(
							'type'      => array( 'string', 'null' ),
							'maxLength' => 100,
						),
						'email_subject'               => array(
							'type'      => 'string',
							'maxLength' => 100,
						),
						'email_body'                  => array(
							'type'      => 'string',
							'maxLength' => 16777215,
						),
						'redirect'                    => array(
							'type'      => 'string',
							'format'    => 'uri',
							'maxLength' => 256,
						),
						'confirm_bcc'                 => array(
							'type'      => 'string',
							'maxLength' => 100,
						),
						'confirm_subject'             => array(
							'type'      => 'string',
							'maxLength' => 100,
						),
						'confirm_body'                => array(
							'type'      => 'string',
							'maxLength' => 16777215,
						),
						'confirm_redirect'            => array(
							'type'      => 'string',
							'maxLength' => 256,
						),
						'emails_needed'               => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'tickets_needed'              => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'invoice_needed'              => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'unique_users_needed'         => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'user_groups_needed'          => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'recaptcha_needed'            => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'confirmation_emails_needed'  => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'confirmation_timeout'        => array(
							'type'    => 'string',
							'pattern' => '^[0-9]+$',
							'minimum' => 0,
						),
						'add_dashboard_orders_needed' => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'test_payments_needed'        => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'seats_needed'                => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'webhooks_needed'             => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'reload_on_exit_needed'       => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'tracking_needed'             => array(
							'type' => 'string',
							'enum' => array( '0', '1' ),
						),
						'terms'                       => array(
							'type'      => array( 'string', 'null' ),
							'maxLength' => 256,
						),
						'pdf_info'                    => array(
							'type'      => 'string',
							'maxLength' => 512,
						),
						'input_fields'                => array(
							'type'      => 'string',
							'maxLength' => 65535,
						),
						'scan_keys'                   => array(
							'type'      => 'string',
							'maxLength' => 65535,
						),
						'tracking_info'               => array(
							'type'      => 'string',
							'maxLength' => 16777215,
						),
					),
					'required'   => array(
						'id',
						'start_date',
						'end_date',
						'event_name',
						'event_date_format',
						'event_date',
						'event_type',
						'stock',
						'sold',
						'group_type',
						'event_group',
						'stock_link',
						'email_bcc',
						'email_subject',
						'email_body',
						'redirect',
						'confirm_bcc',
						'confirm_subject',
						'confirm_body',
						'confirm_redirect',
						'emails_needed',
						'tickets_needed',
						'invoice_needed',
						'unique_users_needed',
						'user_groups_needed',
						'recaptcha_needed',
						'confirmation_emails_needed',
						'confirmation_timeout',
						'add_dashboard_orders_needed',
						'test_payments_needed',
						'seats_needed',
						'webhooks_needed',
						'reload_on_exit_needed',
						'tracking_needed',
						'terms',
						'pdf_info',
						'input_fields',
						'scan_keys',
					),
				),
			),
			'seats'  => array(
				'description' => 'Array of events',
				'type'        => 'array',
				'minItems'    => 0,
				'items'       => array(
					'type'       => 'object',
					'properties' => array(
						'id'           => array(
							'description' => 'The unique id of the seats configuration',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'event_id'     => array(
							'description' => 'The unique id of the event',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'num_seats'    => array(
							'description' => 'Total number of seats',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'last_seat_id' => array(
							'description' => 'The number of the last seat reserved',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'open_seats'   => array(
							'description' => 'The number of seats still available',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'seat_format'  => array(
							'type'      => array( 'string' ),
							'maxLength' => 32,
						),
						'seat_config'  => array(
							'type'      => array( 'string' ),
							'maxLength' => 16777215,
						),
						'seat_map'     => array(
							'type'      => array( 'string' ),
							'maxLength' => 16777215,
						),
						'linked_event' => array(
							'description' => 'Integer field (0 or greater)',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
					),
					'required'   => array(
						'id',
						'event_id',
						'num_seats',
						'last_seat_id',
						'open_seats',
						'seat_format',
						'seat_config',
						'seat_map',
						'linked_event',
					),
				),
			),
			'media'  => array(
				'description' => 'Array of WordPress media files',
				'type'        => 'array',
				'minItems'    => 0,
				'items'       => array(
					'type'       => 'object',
					'properties' => array(
						'id'             => array(
							'description' => 'The unique id of the media post',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'post_title'     => array(
							'type'      => 'string',
							'maxLength' => 16777215,
						),
						'post_mime_type' => array(
							'type'      => 'string',
							'maxLength' => 100,
						),
						'url'            => array(
							'type'   => 'string',
							'format' => 'uri',
						),
					),
					'required'   => array( 'id', 'post_title', 'post_mime_type', 'url' ),
				),
			),
			'pages'  => array(
				'description' => 'Array of WordPress pages',
				'type'        => 'array',
				'minItems'    => 0,
				'items'       => array(
					'type'       => 'object',
					'properties' => array(
						'id'           => array(
							'description' => 'The unique id of the page post',
							'type'        => 'string',
							'pattern'     => '^[0-9]+$',
							'minimum'     => 0,
						),
						'post_name'    => array(
							'type'      => 'string',
							'maxLength' => 200,
						),
						'post_title'   => array(
							'type'      => 'string',
							'maxLength' => 16777215,
						),
						'post_content' => array(
							'type' => 'string',
						),
						'url'          => array(
							'type'   => 'string',
							'format' => 'uri',
						),
					),
					'required'   => array( 'id', 'post_name', 'post_title', 'post_content', 'url' ),
				),
			),
		),
		'required'    => array( 'home', 'events', 'seats', 'media', 'pages' ),
	);
}
