<?php  namespace App\Models;  use Mail; use App\Mail\OrderMail; use App\Traits\HasStorage; use App\Contracts\HasMedia; use App\Observers\OrderObserver; use App\Jobs\GeneratePDFAndSendMailJob; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\HasMany;  class Order extends Model implements HasMedia { 	use HasStorage, Prunable;  	public const MAX_ORDER_ITEMS = 36; 	public const MINIMUM_ITEMS_FOREIGN_COUNTRY = 6;  	public const EUR_EXCHANGE_RATE = 7.53450;  	public const ISLAND_ZIP_CODES = ['20221', '20222', '20223', '20224', '20225', '20226', '20230', '20240', '20242', '20243', '20244', '20245', '20246', '20247', '20248', '20250', '20260', '20261', 		'20262', '20263', '20264', '20267', '20269', '20270', '20271', '20272', '20273', '20274', '20275', '20290', '21225', '21400', '21403', '21404', '21405', '21410', 		'21412', '21413', '21420', '21423', '21424', '21425', '21426', '21430', '21432', '21450', '21454', '21460', '21462', '21463', '21465', '21466', '21467', '21469', 		'21480', '21483', '21485', '22232', '22233', '22234', '22235', '22236', '22240', '22240', '22241', '22242', '22243', '22244', '23212', '23248', '23249', '23250', 		'23251', '23262', '23263', '23264', '23271', '23272', '23273', '23274', '23275', '23281', '23282', '23283', '23284', '23285', '23286', '23287', '23291', '23292', 		'23293', '23294', '23295', '23296', '51280', '51281', '51500', '51511', '51512', '51513', '51514', '51515', '51516', '51517', '51521', '51522', '51523', '51550', 		'51550', '51551', '51552', '51553', '51554', '51555', '51556', '51557', '51559', '51561', '51562', '51564', '53291', '53294', '53296'];  	public const RIJEKA_ZIP_CODES = ['51000', '51215']; 	public const ZAGREB_ZIP_CODES = ['10363', '10257', '10253', '10251', '10373', '10362', '10250', '10360', '10361', '10000', '10110', '10040', '10020', '10010', '10090', '10290']; 	public const ISTRIA_ZIP_CODES = ['52445', '52211', '52207', '52434', '52474', '52460', '52420', '52402', '52449', '52212', '52452', '52216', '52403', '52403', '52352', '52423', '52464', '52222', '52208', '52232', '52220', '52422', '52427', '52204', '52426', '52206', '52203', '52462', '52424', '52231', '52446', '52466', '52428', '52000', '52332', '52234', '52333', '52440', '52100', '52221', '52223', '52425', '52210', '52475', '52448', '52404', '52342', '52233', '52465', '52444', '52224', '52470', '52463', '52447', '52215', '52450', '52341']; 	public const MIDDLE_DALMATIA_ZIP_CODES = ['23420', '23205', '23210', '23286', '23285', '23440', '23293', '23272', '23452', '23251', '23271', '23274', '23292', '23264', '23232', '23312', '23450', '23296', '23250', '23211', '23262', '23231', '23423', '23241', '23242', '23249', '23273', '23294', '23226', '23233', '23283', '23248', '23281', '23291', '23295', '23445', '23422', '23244', '23206', '23207', '23223', '23212', '23245', '23275', '23284', '23287', '23247', '23234', '23235', '23000', '23222', '23263', '23282', 		'22244', '22206', '22214', '22324', '22320', '22301', '22242', '22235', '22310', '22305', '22300', '22221', '22243', '22303', '22205', '22213', '22202', '22233', '22234', '22203', '22322', '22321', '22222', '22000', '22030', '22204', '22240', '22212', '22323', '22211', '22215', '22232', '22236', '22010', '22020', '22304', '22306', '22307', '22311', '22312', '22317', '22318', 		'21246', '21320', '21254', '21228', '21420', '21322', '21454', '21256', '21244', '21229', '21232', '21206', '21205', '21203', '21264', '21275', '21328', '21333', '21225', '21315', '21204', '21253', '21467', '21242', '21271', '21330', '21430', '21233', '21450', '21329', '21260', '21465', '21314', '21262', '21213', '21214', '21215', '21216', '21212', '21217', '21231', '21485', '21207', '21263', '21208', '21202', '21317', '21257', '21404', '21300', '21222', '21405', '21318', '21209', '21247', '21423', 		'21241', '21223', '21310', '21238', '21335', '21327', '21312', '21483', '21410', '21413', '21424', '21201', '21227', '21323', '21412', '21267', '21261', '21425', '21230', '21224', '21272', '21210', '21000', '21292', '21460', '21311', '21432', '21265', '21469', '21400', '21403', '21250', '21245', '21240', '21220', '21325', '21252', '21243', '21277', '21226', '21480', '21462', '21463', '21276', '21236', '21255', '21270', '21334', '21466', '21266', '21251', '21273', ]; 	public const SOUTH_DALMATIA_ZIP_CODES = ['20225', '20357', '20271', '20210', '20273', '20213', '20231', '20216', '20000', '20226', '20215', '20246', '20356', '20221', '20344', '20260', '20267', '20341', '20243', '20290', '20222', '20269', '20263', '20224', '20350', '20207', '20353', '20236', '20278', '20355', '20234', '20250', '20242', '20342', '20340', '20218', '20244', '20217', '20274', '20248', '20264', '20343', '20232', '20272', '20345', '20230', '20223', '20205', '20240', '20245', '20233', '20270', '20352', '20235', '20275', '20247']; 	public const SLAVONIA_ZIP_CODES = ['31551', '31327', '31423', '31432', '31431', '31553', '31326', '31513', '31540', '31418', '31400', '31511', '31512', '31554', '31422', '31416', '31328', '31542', '31555', '31543', '31500', '31417', '31552', '31433', '31530', '31424', '31421', '31415', '31402', '31410', '31411', '31550', '31531', '31401', '31404', '31403', '31000', '31207', '31220', '31300', '31226', '31200', 		'32276', '32247', '32235', '32225', '32227', '32275', '32222', '32272', '32238', '32257', '32244', '32263', '32212', '32273', '32260', '32248', '32236', '32281', '32280', '32253', '32246', '32237', '32213', '32239', '32245', '32221', '32233', '32243', '32211', '32252', '32229', '32258', '32251', '32262', '32261', '32282', '32271', '32242', '32255', '32232', '32241', '32284', '32256', '32234', '32274', '32214', '32249', '32224', '32100', '32283', '32254', '32000', '32010', '32270', 		'33412', '33507', '33514', '33523', '33407', '33411', '33406', '33517', '33518', '33515', '33405', '33533', '33520', '33525', '33410', '33404', '33000', '33522', '33513', 		'34552', '34343', '34322', '34553', '34350', '34308', '34334', '34340', '34311', '34551', '34550', '34310', '34543', '34000', '34315', '34312', '34330', '34335', 		'35254', '35209', '35404', '35214', '35428', '35410', '35430', '35250', '35201', '35107', '35252', '35106', '35105', '35422', ];  	protected $casts = [ 		'is_r1' => 'boolean', 		'is_paid' => 'boolean', 		'is_offer' => 'boolean', 	];  	public function scopeIncludes(Builder $query): Builder{}  	public function mediaConfig(): array{}  	public static function calculateEurosenderShippingPrice(array $items, string $country_code): float 	{ 		$deliveryPriceRow = DeliveryPrice::where('country_code', $country_code)->firstOrFail();  		$quantity = self::countItemsQuantity($items);  		switch ($quantity) { 			case 1: 				return $deliveryPriceRow->price_1_bottle;  			case 2: 				return $deliveryPriceRow->price_2_bottle;  			case 3: 				return $deliveryPriceRow->price_3_bottle;  			case 4: 				return $deliveryPriceRow->price_4_bottle;  			case $quantity <= 6: 				return $deliveryPriceRow->price_6_bottles;  			case $quantity <= 12: 				return $deliveryPriceRow->price_12_bottles;  			case $quantity <= 18: 				return $deliveryPriceRow->price_18_bottles;  			case $quantity <= 24: 				return $deliveryPriceRow->price_24_bottles;  			case $quantity <= 30: 				return $deliveryPriceRow->price_30_bottles;  			case $quantity <= 36: 				return $deliveryPriceRow->price_36_bottles; 		}  		return 0; 	}  	public static function countItemsQuantity(array $items): int 	{ 		$quantity_count = 0;  		foreach ($items as $item) { 			$quantity_count += $item['quantity']; 		}  		return $quantity_count; 	}  	public static function isIslandDelivery(string $zipcode): bool 	{ 		return in_array($zipcode, self::ISLAND_ZIP_CODES); 	}  	public static function checkDeliveryServiceAndCalculateShipping(string $delivery_country, string $delivery_zip_code, array $items, float $totalWeight): float 	{ 		$shipping_price = 0;  		$shipping_price = strtoupper($delivery_country) == 'HR' ? self::calculateLagermaxShipping($delivery_zip_code, $totalWeight) : self::calculateEurosenderShippingPrice($items, $delivery_country);  		if (strtoupper($delivery_country) != 'HR') { // if Eurosender ,add price per box on shipping price 			$shipping_price += ceil(round(self::countItemsQuantity($items) / 6, 2)) * setting('package_price'); 		}  		if (strtoupper($delivery_country) == 'HR' && self::isIslandDelivery($delivery_zip_code)) { 			$shipping_price += $shipping_price * (setting('lagermax_island_percentage') / 100); 		}  		return $shipping_price; 	}  	public static function calculateLagermaxShipping(string $delivery_zip_code, float $totalWeight): float 	{ 		if ($totalWeight >= 500 && $totalWeight <= 800) { 			switch ($delivery_zip_code) { 				case in_array($delivery_zip_code, self::ISTRIA_ZIP_CODES): 					return setting('lagermax_istra_from_500kg_to_800kg');  				case in_array($delivery_zip_code, self::RIJEKA_ZIP_CODES): 					return setting('lagermax_rijeka_from_500kg_to_800kg');  				case in_array($delivery_zip_code, self::ZAGREB_ZIP_CODES): 					return setting('lagermax_zagreb_from_500kg_to_800kg');  				case in_array($delivery_zip_code, self::SLAVONIA_ZIP_CODES): 					return setting('lagermax_slavonia_from_500kg_to_800kg');  				case in_array($delivery_zip_code, self::MIDDLE_DALMATIA_ZIP_CODES): 					return setting('lagermax_m_dalmatia_from_500kg_to_800kg');  				case in_array($delivery_zip_code, self::SOUTH_DALMATIA_ZIP_CODES): 					return setting('lagermax_s_dalmatia_from_500kg_to_800kg'); 			} 		} elseif ($totalWeight < 500) { 			return $totalWeight < 1 ? setting('lagermax_price_up_to_35kg') : ceil(round($totalWeight / 35, 2)) * setting('lagermax_price_up_to_35kg'); 		}  		return 0; 	}  	public function handleOfferMail(): self{}  	public function handleOrderMail(): self{}  	public function generatePDF(string $viewName, string $PDFName): void{}  	public function dispatchGeneratePDFSendEmail(string $PDFView, string $PDFName, string $mailView, string $mailSubject, bool $now = false): self{}  	public function sendMail(string $mailView, string $subject): void{}  	public function scopePaid(Builder $query): Builder{}  	public function orderItems(): HasMany{}  	public function setFullNameAttribute(string $value): void{}  	public function setDeliveryCountryAttribute(string $value): void{}  	public function setDeliveryCityAttribute(string $value): void{}  	public function setDeliveryAddressAttribute(string $value): void{}  	public function setDeliveryZipCodeAttribute(string $value): void{}  	public function setBillableCountryAttribute(string $value): void{}  	public function setBillableCityAttribute(string $value): void{}  	public function setBillableAddressAttribute(string $value): void{}  	public function setBillableZipCodeAttribute(string $value): void{}  	public function setVatNumberAttribute(?string $value): void{}  	public function setDescriptionAttribute(?string $value): void{}  	public function prunable(): Builder{}  	protected static function initObservers(): ?string 	{ 		return OrderObserver::class; 	} }