from rest_framework import serializers

from .models import ZasilkovnaPacket, ZasilkovnaShipment


class ZasilkovnaPacketSerializer(serializers.ModelSerializer):
	class Meta:
		model = ZasilkovnaPacket
		fields = [
			"id",
			"created_at",
			"packet_id",
			"barcode",
			"state",
			"weight",
			"return_routing",
		]
		read_only_fields = [
			"id",
			"created_at",
			"barcode",
			"state",
			"weight",
			"return_routing",
		]


#Just for tracking URL of packet
class TrackingURLSerializer(serializers.Serializer):
	barcode = serializers.CharField(read_only=True)
	tracking_url = serializers.URLField(read_only=True)



# -- SHIPMENT --

class ZasilkovnaShipmentSerializer(serializers.ModelSerializer):
	packets = serializers.PrimaryKeyRelatedField(
		many=True,
		queryset=ZasilkovnaPacket.objects.all()	
	)

	class Meta:
		model = ZasilkovnaShipment
		fields = [
			"id",
			"created_at",
			"shipment_id",
			"barcode",
			"packets", 
		]
		read_only_fields = [
			"id",
			"created_at",
			"shipment_id",
			"barcode",
		]
