<?php

declare(strict_types=1);

namespace svoboda\pechatalka\models\enumerations\paper;

// Files of the project
use svoboda\pechatalka\models\enumerations\product\type as product_type;

/**
 * Types of products
 *
 * @package svoboda\pechatalka\models\enumerations\paper
 *
 * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
 * @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
 */
enum format
{
	case a6;

	/**
	 * Dimensions
	 *
	 * @return array The paper format dimensions in centimeters (cm) ['width', 'height']
	 */
	public function dimensions(): array
	{
		return match ($this) {
			format::a6 => [
				'width' => 10.5,
				'height' => 14.8
			]
		};
	}

	/**
	 * Places
	 *
	 * @param product_type $type The product type
	 * @param int|float $padding The paper padding (print borders)
	 *
	 * @return array The paper places by the product type in centimeters (cm)
	 */
	public function places(product_type $type, int|float $padding = 0): array|false
	{
		if ($this === format::a6) {
			// A6

			// Initializing the paper dimensions
			$paper = $this->dimensions();

			if ($type === product_type::pin_37) {
				// Pin 37mm

				// Initializing the product dimensions
				$blank = $type->areas()['blank'];

				// Calculating the general X coordinate
				$x = $paper['width'] / 2 - $blank['width'] / 2 - $padding;

				// Initializing the amount of products
				$amount = 2;
	
				// Calculating the summary products height
				$height = $blank['height'] * $amount;

				// Calculating the free space on the page
				$free = $paper['height'] - $padding * 2 - $height;

				// Calculating the offset between products and from products to the paper borders
				$offset = $free / ($amount + 1);

				// Exit (success)
				return [
					[
						'x' => $x,
						'y' => $offset
					],
					[
						'x' => $x,
						'y' => $offset + $blank['height'] + $offset
					],
				];
			}
		}

		// Exit (fail)
		return false;
	}
}
