<?php
/**
 * Schema for pdf_info.
 *
 * @package Fast-Events/Schema
 * @since 1.0
 */

declare(strict_types=1);

/**
 * Return the pdf_info schema.
 *
 * @return array
 */
function fast_events_schema_pdf_info(): array {
	return array(
		'$schema'     => 'http =>//json-schema.org/draft-04/schema#',
		'title'       => 'Ticket and invoice PDF',
		'description' => 'Field locations on ticket and invoice PDF for the Fast Events WordPress plugin',
		'type'        => 'object',
		'properties'  => array(
			'ticket'  => array(
				'description' => 'Qrcode block position in ticket PDF',
				'type'        => 'object',
				'properties'  => array(
					'id'        => array(
						'description' => 'The id of attachment in de WordPress media store',
						'type'        => 'integer',
						'minimum'     => 0,
					),
					'x'         => array(
						'description' => 'X position on A4 PDF',
						'type'        => 'integer',
						'minimum'     => 0,
						'maximum'     => 210,
					),
					'y'         => array(
						'description' => 'Y position on A4 PDF',
						'type'        => 'integer',
						'minimum'     => 0,
						'maximum'     => 297,
					),
					'rotate'    => array(
						'description' => 'Rotate the qrcode block by degrees',
						'type'        => 'integer',
					),
					'scale'     => array(
						'description' => 'Scale the qrcode block',
						'type'        => 'integer',
					),
					'no_border' => array(
						'description' => 'Is a borderline needed',
						'type'        => 'integer',
						'enum'        => array( 0, 1 ),
					),
					'types'     => array(
						'description'       => 'All ticket types with their attachment-id',
						'type'              => 'object',
						'patternProperties' => array(
							'^[^,]{3,30}$'         => array(
								'description' => 'The id of attachment in de WordPress media store',
								'type'        => 'integer',
								'minimum'     => 0,
							),
							'additionalProperties' => false,
						),
					),
				),
				'required'    => array( 'id', 'x', 'y', 'rotate', 'types' ),
			),
			'invoice' => array(
				'description' => 'Positions element on invoice PDF',
				'type'        => 'object',
				'properties'  => array(
					'id'        => array(
						'description' => 'The id of attachment in de WordPress media store',
						'type'        => array( 'string', 'integer' ),
					),
					'vat'       => array(
						'Description' => 'Is VAT being used',
						'type'        => 'integer',
						'enum'        => array( 0, 1 ),
					),
					'name'      => array(
						'description' => 'Position of the name field',
						'type'        => 'object',
						'properties'  => array(
							'x' => array(
								'description' => 'X position on A4 PDF',
								'type'        => 'integer',
								'minimum'     => 0,
								'maximum'     => 210,
							),
							'y' => array(
								'description' => 'Y position on A4 PDF',
								'type'        => 'integer',
								'minimum'     => 0,
								'maximum'     => 297,
							),
						),
						'required'    => array( 'x', 'y' ),
					),
					'invoiceno' => array(
						'description' => 'Position of the invoice number field',
						'type'        => 'object',
						'properties'  => array(
							'x' => array(
								'description' => 'X position on A4 PDF',
								'type'        => 'integer',
								'minimum'     => 0,
								'maximum'     => 210,
							),
							'y' => array(
								'description' => 'Y position on A4 PDF',
								'type'        => 'integer',
								'minimum'     => 0,
								'maximum'     => 297,
							),
						),
						'required'    => array( 'x', 'y' ),
					),
					'line'      => array(
						'description' => 'Position of the first invoice line',
						'type'        => 'object',
						'properties'  => array(
							'x' => array(
								'description' => 'X position on A4 PDF',
								'type'        => 'integer',
								'minimum'     => 0,
								'maximum'     => 210,
							),
							'y' => array(
								'description' => 'Y position on A4 PDF',
								'type'        => 'integer',
								'minimum'     => 0,
								'maximum'     => 297,
							),
							'w' => array(
								'description' => 'Width of the invoice line',
								'type'        => 'integer',
								'minimum'     => 0,
								'maximum'     => 210,
							),
						),
						'required'    => array( 'x', 'y', 'w' ),
					),
				),
				'required'    => array( 'name', 'invoiceno', 'line' ),
			),
		),
		'required'    => array( 'ticket', 'invoice' ),
	);
}
