protected function prepareOffset(int $offset, int $total): int
    {
        if ($offset < -$total || $offset > $total - 1) {
            $message = sprintf('Offset (%d) out of range[%d, %d]', $offset, -$total, $total - 1);
            throw new DomainException($message);
        }

        if ($offset < 0) {
            $offset += $total;
        }

        return $offset;
    }