<?php



class WooModel extends BaseModel {



	public function __construct() {

		parent::__construct("WooTransport", [WOOREST_HOST, WOOREST_CK, WOOREST_CS]);

	}



	/* ORDER */



	public function getOrder($orderId) {

		return $this->transport()->get("orders/{$orderId}");

	}

	public function putOrder($orderId, $data) {

		return $this->transport()->put("orders/{$orderId}", $data, "put");

	}





	/* PRODUCT */



	public function getProducts($filters = []) {

		$params = [];

		foreach ($filters as $key => $value) {

			$params[] = urlencode($key) . "=" . urlencode($value);

		}

		return $this->transport()->get("products?" . implode("&", $params));

	}

	public function getProduct($productId) {

		return $this->transport()->get("products/{$productId}");

	}

	public function getVariations($productId) {

		return $this->transport()->get("products/{$productId}/variations");

	}

	public function putProduct($productId, $data) {

		return $this->transport()->put("products/{$productId}", $data);

	}

	public function addProduct($data) {

		return $this->transport()->post("products", $data);

	}

	public function updateProductBrand($sku, $brand) {

		try {

			$brandActionUrl = "https://lazyhouse.lt/namu-scripts/finishImportProduct.php";

			$requestData = [

				"action" => "brand",

				"sku" => $sku,

				"brand" => $brand,

			];

			$result = $this->transport()->simpleGet($brandActionUrl, $requestData);

			return true;

		} catch (Exception $e) {

			return false;

		}

	}



	public function getAttributes() {

		return $this->transport()->get("products/attributes");

	}

	public function addAttribute($data) {

		return $this->transport()->post("products/attributes", $data);

	}

	





}