<?php

declare(strict_types=1);

namespace ShopManagerPro\Products\DTO\Generated;

class ProductBasic {
	private static array $schema = ['type' => 'object', 'required' => ['id', 'parentId', 'name', 'descriptionLong', 'descriptionShort', 'imageId', 'galleryImageIds', 'postStatus', 'sku', 'regularPrice', 'salePrice', 'stock', 'stockStatus', 'taxClass', 'taxStatus', 'totalSales'], 'properties' => ['id' => ['type' => 'integer'], 'parentId' => ['type' => 'integer'], 'name' => ['type' => 'string'], 'descriptionLong' => ['type' => 'string'], 'descriptionShort' => ['type' => 'string'], 'imageId' => ['oneOf' => [['type' => 'integer'], ['type' => 'null']]], 'galleryImageIds' => ['type' => 'array', 'items' => ['type' => 'integer']], 'postStatus' => ['type' => 'string', 'enum' => ['draft', 'pending', 'private', 'publish', 'trash']], 'sku' => ['type' => 'string'], 'regularPrice' => ['oneOf' => [['type' => 'number'], ['type' => 'null']]], 'salePrice' => ['oneOf' => [['type' => 'number'], ['type' => 'null']]], 'stock' => ['oneOf' => [['type' => 'integer'], ['type' => 'null']]], 'stockStatus' => ['oneOf' => [['type' => 'string', 'enum' => ['instock', 'onbackorder', 'outofstock']], ['type' => 'null']]], 'taxClass' => ['oneOf' => [['type' => 'string'], ['type' => 'null']]], 'taxStatus' => ['oneOf' => [['type' => 'string', 'enum' => ['none', 'shipping', 'taxable']], ['type' => 'null']]], 'totalSales' => ['type' => 'integer']]];
	private int $id;
	private int $parentId;
	private string $name;
	private string $descriptionLong;
	private string $descriptionShort;
	private $imageId;
	private array $galleryImageIds;
	private ProductBasicPostStatus $postStatus;
	private string $sku;
	private $regularPrice;
	private $salePrice;
	private $stock;
	private $stockStatus;
	private $taxClass;
	private $taxStatus;
	private int $totalSales;

	public function __construct(int $id, int $parentId, string $name, string $descriptionLong, string $descriptionShort, $imageId, array $galleryImageIds, ProductBasicPostStatus $postStatus, string $sku, $regularPrice, $salePrice, $stock, $stockStatus, $taxClass, $taxStatus, int $totalSales) {
		$this->id = $id;
		$this->parentId = $parentId;
		$this->name = $name;
		$this->descriptionLong = $descriptionLong;
		$this->descriptionShort = $descriptionShort;
		$this->imageId = $imageId;
		$this->galleryImageIds = $galleryImageIds;
		$this->postStatus = $postStatus;
		$this->sku = $sku;
		$this->regularPrice = $regularPrice;
		$this->salePrice = $salePrice;
		$this->stock = $stock;
		$this->stockStatus = $stockStatus;
		$this->taxClass = $taxClass;
		$this->taxStatus = $taxStatus;
		$this->totalSales = $totalSales;
	}

	public function getId(): int {
		return $this->id;
	}

	public function getParentId(): int {
		return $this->parentId;
	}

	public function getName(): string {
		return $this->name;
	}

	public function getDescriptionLong(): string {
		return $this->descriptionLong;
	}

	public function getDescriptionShort(): string {
		return $this->descriptionShort;
	}

	public function getImageId() {
		return $this->imageId;
	}

	public function getGalleryImageIds(): array {
		return $this->galleryImageIds;
	}

	public function getPostStatus(): ProductBasicPostStatus {
		return $this->postStatus;
	}

	public function getSku(): string {
		return $this->sku;
	}

	public function getRegularPrice() {
		return $this->regularPrice;
	}

	public function getSalePrice() {
		return $this->salePrice;
	}

	public function getStock() {
		return $this->stock;
	}

	public function getStockStatus() {
		return $this->stockStatus;
	}

	public function getTaxClass() {
		return $this->taxClass;
	}

	public function getTaxStatus() {
		return $this->taxStatus;
	}

	public function getTotalSales(): int {
		return $this->totalSales;
	}

	public function withId(int $id): self {
		$validator = new \JsonSchema\Validator();
		$validator->validate($id, self::$schema['properties']['id']);
		if (!$validator->isValid()) {
			throw new \InvalidArgumentException($validator->getErrors()[0]['message']);
		} $clone = clone $this;
		$clone->id = $id;

		return $clone;
	}

	public function withParentId(int $parentId): self {
		$validator = new \JsonSchema\Validator();
		$validator->validate($parentId, self::$schema['properties']['parentId']);
		if (!$validator->isValid()) {
			throw new \InvalidArgumentException($validator->getErrors()[0]['message']);
		} $clone = clone $this;
		$clone->parentId = $parentId;

		return $clone;
	}

	public function withName(string $name): self {
		$validator = new \JsonSchema\Validator();
		$validator->validate($name, self::$schema['properties']['name']);
		if (!$validator->isValid()) {
			throw new \InvalidArgumentException($validator->getErrors()[0]['message']);
		} $clone = clone $this;
		$clone->name = $name;

		return $clone;
	}

	public function withDescriptionLong(string $descriptionLong): self {
		$validator = new \JsonSchema\Validator();
		$validator->validate($descriptionLong, self::$schema['properties']['descriptionLong']);
		if (!$validator->isValid()) {
			throw new \InvalidArgumentException($validator->getErrors()[0]['message']);
		} $clone = clone $this;
		$clone->descriptionLong = $descriptionLong;

		return $clone;
	}

	public function withDescriptionShort(string $descriptionShort): self {
		$validator = new \JsonSchema\Validator();
		$validator->validate($descriptionShort, self::$schema['properties']['descriptionShort']);
		if (!$validator->isValid()) {
			throw new \InvalidArgumentException($validator->getErrors()[0]['message']);
		} $clone = clone $this;
		$clone->descriptionShort = $descriptionShort;

		return $clone;
	}

	public function withImageId($imageId): self {
		$clone = clone $this;
		$clone->imageId = $imageId;

		return $clone;
	}

	public function withGalleryImageIds(array $galleryImageIds): self {
		$validator = new \JsonSchema\Validator();
		$validator->validate($galleryImageIds, self::$schema['properties']['galleryImageIds']);
		if (!$validator->isValid()) {
			throw new \InvalidArgumentException($validator->getErrors()[0]['message']);
		} $clone = clone $this;
		$clone->galleryImageIds = $galleryImageIds;

		return $clone;
	}

	public function withPostStatus(ProductBasicPostStatus $postStatus): self {
		$clone = clone $this;
		$clone->postStatus = $postStatus;

		return $clone;
	}

	public function withSku(string $sku): self {
		$validator = new \JsonSchema\Validator();
		$validator->validate($sku, self::$schema['properties']['sku']);
		if (!$validator->isValid()) {
			throw new \InvalidArgumentException($validator->getErrors()[0]['message']);
		} $clone = clone $this;
		$clone->sku = $sku;

		return $clone;
	}

	public function withRegularPrice($regularPrice): self {
		$clone = clone $this;
		$clone->regularPrice = $regularPrice;

		return $clone;
	}

	public function withSalePrice($salePrice): self {
		$clone = clone $this;
		$clone->salePrice = $salePrice;

		return $clone;
	}

	public function withStock($stock): self {
		$clone = clone $this;
		$clone->stock = $stock;

		return $clone;
	}

	public function withStockStatus($stockStatus): self {
		$clone = clone $this;
		$clone->stockStatus = $stockStatus;

		return $clone;
	}

	public function withTaxClass($taxClass): self {
		$clone = clone $this;
		$clone->taxClass = $taxClass;

		return $clone;
	}

	public function withTaxStatus($taxStatus): self {
		$clone = clone $this;
		$clone->taxStatus = $taxStatus;

		return $clone;
	}

	public function withTotalSales(int $totalSales): self {
		$validator = new \JsonSchema\Validator();
		$validator->validate($totalSales, self::$schema['properties']['totalSales']);
		if (!$validator->isValid()) {
			throw new \InvalidArgumentException($validator->getErrors()[0]['message']);
		} $clone = clone $this;
		$clone->totalSales = $totalSales;

		return $clone;
	}

	public static function buildFromInput(array|object $input, bool $validate = true): ProductBasic {
		$input = is_array($input) ? \JsonSchema\Validator::arrayToObjectRecursive($input) : $input;
		if ($validate) {
			static::validateInput($input);
		} $id = (int) $input->{'id'};
		$parentId = (int) $input->{'parentId'};
		$name = $input->{'name'};
		$descriptionLong = $input->{'descriptionLong'};
		$descriptionShort = $input->{'descriptionShort'};
		$imageId = match (true) {
			is_int($input->{'imageId'}), true => $input->{'imageId'}, default => throw new \InvalidArgumentException("could not build property 'imageId' from JSON"),
		};
		$galleryImageIds = $input->{'galleryImageIds'};
		$postStatus = ProductBasicPostStatus::from($input->{'postStatus'});
		$sku = $input->{'sku'};
		$regularPrice = match (true) {
			is_int($input->{'regularPrice'}) || is_float($input->{'regularPrice'}), true => $input->{'regularPrice'}, default => throw new \InvalidArgumentException("could not build property 'regularPrice' from JSON"),
		};
		$salePrice = match (true) {
			is_int($input->{'salePrice'}) || is_float($input->{'salePrice'}), true => $input->{'salePrice'}, default => throw new \InvalidArgumentException("could not build property 'salePrice' from JSON"),
		};
		$stock = match (true) {
			is_int($input->{'stock'}), true => $input->{'stock'}, default => throw new \InvalidArgumentException("could not build property 'stock' from JSON"),
		};
		$stockStatus = match (true) {
			ProductBasicStockStatusAlternative1::tryFrom($input->{'stockStatus'}) !== null => ProductBasicStockStatusAlternative1::from($input->{'stockStatus'}), true => $input->{'stockStatus'}, default => throw new \InvalidArgumentException("could not build property 'stockStatus' from JSON"),
		};
		$taxClass = match (true) {
			is_string($input->{'taxClass'}), true => $input->{'taxClass'}, default => throw new \InvalidArgumentException("could not build property 'taxClass' from JSON"),
		};
		$taxStatus = match (true) {
			ProductBasicTaxStatusAlternative1::tryFrom($input->{'taxStatus'}) !== null => ProductBasicTaxStatusAlternative1::from($input->{'taxStatus'}), true => $input->{'taxStatus'}, default => throw new \InvalidArgumentException("could not build property 'taxStatus' from JSON"),
		};
		$totalSales = (int) $input->{'totalSales'};
		$obj = new self($id, $parentId, $name, $descriptionLong, $descriptionShort, $imageId, $galleryImageIds, $postStatus, $sku, $regularPrice, $salePrice, $stock, $stockStatus, $taxClass, $taxStatus, $totalSales);

		return $obj;
	}

	public function toJson(): array {
		$output = [];
		$output['id'] = $this->id;
		$output['parentId'] = $this->parentId;
		$output['name'] = $this->name;
		$output['descriptionLong'] = $this->descriptionLong;
		$output['descriptionShort'] = $this->descriptionShort;
		$output['imageId'] = match (true) {
			is_int($this->imageId), true => $this->imageId,
		};
		$output['galleryImageIds'] = $this->galleryImageIds;
		$output['postStatus'] = $this->postStatus->value;
		$output['sku'] = $this->sku;
		$output['regularPrice'] = match (true) {
			is_int($this->regularPrice) || is_float($this->regularPrice), true => $this->regularPrice,
		};
		$output['salePrice'] = match (true) {
			is_int($this->salePrice) || is_float($this->salePrice), true => $this->salePrice,
		};
		$output['stock'] = match (true) {
			is_int($this->stock), true => $this->stock,
		};
		$output['stockStatus'] = match (true) {
			$this->stockStatus instanceof ProductBasicStockStatusAlternative1 => $this->stockStatus->value, true => $this->stockStatus,
		};
		$output['taxClass'] = match (true) {
			is_string($this->taxClass), true => $this->taxClass,
		};
		$output['taxStatus'] = match (true) {
			$this->taxStatus instanceof ProductBasicTaxStatusAlternative1 => $this->taxStatus->value, true => $this->taxStatus,
		};
		$output['totalSales'] = $this->totalSales;

		return $output;
	}

	public static function validateInput(array|object $input, bool $return = false): bool {
		$validator = new \JsonSchema\Validator();
		$input = is_array($input) ? \JsonSchema\Validator::arrayToObjectRecursive($input) : $input;
		$validator->validate($input, self::$schema);
		if (!$validator->isValid() && !$return) {
			$errors = array_map(function (array $e): string { return $e['property'].': '.$e['message']; }, $validator->getErrors());
			throw new \InvalidArgumentException(join(', ', $errors));
		}

return $validator->isValid();
	}

	public function __clone() {
		$this->imageId = match (true) {
			is_int($this->imageId), true => $this->imageId,
		};
		$this->regularPrice = match (true) {
			is_int($this->regularPrice) || is_float($this->regularPrice), true => $this->regularPrice,
		};
		$this->salePrice = match (true) {
			is_int($this->salePrice) || is_float($this->salePrice), true => $this->salePrice,
		};
		$this->stock = match (true) {
			is_int($this->stock), true => $this->stock,
		};
		$this->stockStatus = match (true) {
			$this->stockStatus instanceof ProductBasicStockStatusAlternative1, true => $this->stockStatus,
		};
		$this->taxClass = match (true) {
			is_string($this->taxClass), true => $this->taxClass,
		};
		$this->taxStatus = match (true) {
			$this->taxStatus instanceof ProductBasicTaxStatusAlternative1, true => $this->taxStatus,
		};
	}
}
