public function normalize($shipment, $format = null, array $context = [])
    {
        $data = parent::normalize($shipment, $format, $context);

        if ($this->contextHasGroup(['Default', 'OrderShipment'], $context)) {
            $sale = $shipment->getSale();

            $data = array_replace($data, [
                'number'          => $shipment->getNumber(),
                'company'         => $sale->getCompany(),
                'email'           => $sale->getEmail(),
                'first_name'      => $sale->getFirstName(),
                'last_name'       => $sale->getLastName(),
                'type'            => $shipment->isReturn() ? 'return' : 'shipment',
                'method'          => $shipment->getMethod()->getName(),
                'tracking_number' => $shipment->getTrackingNumber(),
                'description'     => $shipment->getDescription(),
            ]);
        } elseif ($this->contextHasGroup('Summary', $context)) {
            $items = [];
            $parcels = [];

            foreach ($shipment->getItems() as $item) {
                $items[] = $this->normalizeObject($item, $format, $context);
            }
            foreach ($shipment->getParcels() as $parcel) {
                $parcels[] = $this->normalizeObject($parcel, $format, $context);
            }

            $data = array_replace($data, [
                'items'           => $items,
                'parcels'         => $parcels,
                'description'     => $shipment->getDescription(),
                'tracking_number' => $shipment->getTrackingNumber(),
                'valorization'    => $shipment->getValorization(),
            ]);
        }

        return $data;
    }
public function normalize($shipment, $format = null, array $context = [])
    {
        $data = parent::normalize($shipment, $format, $context);

        if ($this->contextHasGroup(['Default', 'OrderShipment'], $context)) {
            $sale = $shipment->getSale();

            $data = array_replace($data, [
                'number'          => $shipment->getNumber(),
                'company'         => $sale->getCompany(),
                'email'           => $sale->getEmail(),
                'first_name'      => $sale->getFirstName(),
                'last_name'       => $sale->getLastName(),
                'type'            => $shipment->isReturn() ? 'return' : 'shipment',
                'method'          => $shipment->getMethod()->getName(),
                'tracking_number' => $shipment->getTrackingNumber(),
                'description'     => $shipment->getDescription(),
            ]);
        } elseif ($this->contextHasGroup('Summary', $context)) {
            $items = [];
            $parcels = [];

            foreach ($shipment->getItems() as $item) {
                $items[] = $this->normalizeObject($item, $format, $context);
            }
            foreach ($shipment->getParcels() as $parcel) {
                $parcels[] = $this->normalizeObject($parcel, $format, $context);
            }

            $data = array_replace($data, [
                'items'           => $items,
                'parcels'         => $parcels,
                'description'     => $shipment->getDescription(),
                'tracking_number' => $shipment->getTrackingNumber(),
                'valorization'    => $shipment->getValorization(),
            ]);
        }

        return $data;
    }
@inheritdoc

@param ShipmentInterface $shipment