<?php
/**
 * Product model for campaigns.
 *
 * @package flo-sync
 */

namespace NMFS\Sync\Items\Campaigns\Models;

defined( 'ABSPATH' ) || exit;

/**
 * Class Product_Model
 */
class Product_Model {


	/**
	 * Product name.
	 *
	 * @var string
	 */
	protected string $name;

	/**
	 * Product SKU.
	 *
	 * @var string
	 */
	protected string $sku;

	/**
	 * Product price.
	 *
	 * @var float
	 */
	protected float $price = 0.0;

	/**
	 * Product discount.
	 *
	 * @var float
	 */
	protected float $discount = 0.0;

	/**
	 * Product VAT rate.
	 *
	 * @var int
	 */
	protected int $vat_rate;

	/**
	 * Uses of this product.
	 *
	 * @var int
	 */
	protected int $uses = 0;

	/**
	 * Product_Model constructor.
	 *
	 * @param string $name     Product name.
	 * @param string $sku      Product SKU.
	 * @param float  $price    Price inc VAT.
	 * @param int    $vat_rate VAT rate in percent.
	 */
	public function __construct( string $name, string $sku, float $price, int $vat_rate ) {
		$this->set_name( $name );
		$this->set_sku( $sku );
		$this->set_price( $price );
		$this->vat_rate = $vat_rate;
	}

	/**
	 * Gets the product name.
	 *
	 * @return string
	 */
	public function get_name(): string {
		return $this->name;
	}

	/**
	 * Sets the product name.
	 *
	 * @param string $name The name.
	 */
	public function set_name( string $name ): void {
		$this->name = $name;
	}

	/**
	 * Gets the product SKU.
	 *
	 * @return string
	 */
	public function get_sku(): string {
		return $this->sku;
	}

	/**
	 * Sets the product SKU.
	 *
	 * @param string $sku The SKU.
	 */
	public function set_sku( string $sku ): void {
		$this->sku = $sku;
	}

	/**
	 * Gets the product price.
	 *
	 * @return float
	 */
	public function get_price(): float {
		return $this->price;
	}

	/**
	 * Sets the product price.
	 *
	 * @param float $price The price.
	 */
	public function set_price( float $price ): void {
		$this->price = $price;
	}

	/**
	 * Gets discount
	 *
	 * @param bool $remove_vat Set this to true to remove vat of discount. Used if prices are ex tax in Woo.
	 *
	 * @return float
	 */
	public function get_discount( bool $remove_vat = false ): float {
		return $remove_vat
			? $this->discount / ( 1 + ( $this->vat_rate / 100.0 ) )
			: $this->discount;
	}

	/**
	 * Sets the discount.
	 *
	 * @param float $discount The discount.
	 */
	public function set_discount( float $discount ): void {
		$this->discount = $discount;
	}

	/**
	 * Gets the uses of this product.
	 *
	 * @return int
	 */
	public function get_uses(): int {
		return $this->uses;
	}

	/**
	 * Adds a use to this product.
	 */
	public function add_use(): void {
		++$this->uses;
	}
}
