<?php

namespace PostenBringCheckout\admin\bring\models\service;

defined( 'ABSPATH' ) || exit;

class MaxEdges {
	public int $max_longest_edge;
	public int $max_sum_of_edges;

	public function __construct( array $data ) {
		$this->max_longest_edge = $data['maxLongestEdge'];
		$this->max_sum_of_edges = $data['maxSumOfEdges'];
	}

	public static function fits_within_edges( ?MaxEdges $max_edges, int $height, int $width, int $length ): bool {
		$provided = array( $height, $length, $width );
		rsort( $provided );
		return empty( $max_edges ) || ( $max_edges->max_sum_of_edges >= $length + $length + $width && $max_edges->max_longest_edge >= $provided[0] );
	}
}
