<?php

namespace Simplyin\Simplyin_W_Plugin\Dto\Order;

use Simplyin\Simplyin_W_Plugin\Dto\Abstract_Item_DTO;

class Order_Item_DTO extends Abstract_Item_DTO {

	protected string $name;
	protected string $url;
	protected float $price_net;
	protected float $price;
	protected float $total_amount;
	protected float $tax_amount;
	protected float $tax_rate;
	protected int $quantity;
	protected string $thumbnail_url;
	protected string $currency;
	protected ?string $sku = null;
	protected ?string $ean = null;
	protected ?string $brand = null;
	/** @var array<int, array{name: string, value: string}> */
	protected array $attributes = [];

	public function to_array(): array {
		$data = [
			'name'         => $this->name,
			'url'          => $this->url,
			'price_net'    => $this->price_net,
			'price'        => $this->price,
			'total_amount' => $this->total_amount,
			'quantity'     => $this->quantity,
			'tax_amount'   => $this->tax_amount,
			'tax_rate'     => $this->tax_rate,
			'thumbnailUrl' => $this->thumbnail_url,
			'currency'     => $this->currency,
		];

		// Optional product attributes — sent only when present, so older shops and
		// products without the data stay backward-compatible and an order is never
		// blocked by missing attribute data.
		if ( null !== $this->sku && '' !== $this->sku ) {
			$data['sku'] = $this->sku;
		}
		if ( null !== $this->ean && '' !== $this->ean ) {
			$data['ean'] = $this->ean;
		}
		if ( null !== $this->brand && '' !== $this->brand ) {
			$data['brand'] = $this->brand;
		}
		if ( ! empty( $this->attributes ) ) {
			$data['attributes'] = $this->attributes;
		}

		return $data;
	}

	public function set_name( string $name ): void {
		$this->name = $name;
	}

	public function set_url( string $url ): void {
		$this->url = $url;
	}

	public function set_price( float $price ): void {
		$this->price = $price;
	}

	public function set_quantity( int $quantity ): void {
		$this->quantity = $quantity;
	}

	public function set_thumbnail_url( string $thumbnail_url ): void {
		$this->thumbnail_url = $thumbnail_url;
	}

	public function set_currency( string $currency ): void {
		$this->currency = $currency;
	}

	public function set_price_net( float $price_net ): void {
		$this->price_net = $price_net;
	}

	public function set_tax_amount( float $tax_amount ): void {
		$this->tax_amount = $tax_amount;
	}

	public function set_tax_rate( float $tax_rate ): void {
		$this->tax_rate = $tax_rate;
	}

	public function set_total_amount( float $total_amount ): void {
		$this->total_amount = $total_amount;
	}

	public function set_sku( ?string $sku ): void {
		$this->sku = $sku;
	}

	public function set_ean( ?string $ean ): void {
		$this->ean = $ean;
	}

	public function set_brand( ?string $brand ): void {
		$this->brand = $brand;
	}

	/**
	 * @param array<int, array{name: string, value: string}> $attributes
	 */
	public function set_attributes( array $attributes ): void {
		$this->attributes = $attributes;
	}
}
