<?php 
class ModelModuleStockStatusOnMailOrder extends Model {

	public function getStockStatus($product_id) {

		if($this->checkStatus()){

			return $this->stockMessage($this->db->query("SELECT quantity FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'")->row['quantity']);		
		}
	}

	private function stockMessage($stock){

		foreach ($this->config->get('stock_status_on_mail_order_options') as $option) {
			if($stock < $option['quantity']){
				return $this->getStockStatusName($option['stock_status_id']);
			}
		}
	}

	private function getStockStatusName($stock_status_id){
		return $this->db->query("SELECT name FROM " . DB_PREFIX . "stock_status WHERE stock_status_id = '" . (int)$stock_status_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'")->row['name'];
	}

	public function checkStatus(){
		return (bool) $this->config->get('stock_status_on_mail_order_status');   
	}
}
