from rest_framework import serializers
from .models import SalesOrder, SalesOrderLine


class SalesOrderSerializer(serializers.HyperlinkedModelSerializer):
    sales_order_lines = serializers.HyperlinkedRelatedField(
        many=True, read_only=True, view_name="salesorderline-detail"
    )

    class Meta:
        model = SalesOrder
        fields = [
            "url",
            "id",
            "customer",
            "shipped_on",
            "complete",
            "value",
            "shipped_value",
            "sales_order_lines",
        ]


class SalesOrderLineSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = SalesOrderLine
        read_only_fields = ["complete_date", "value"]
        fields = [
            "url",
            "id",
            "sales_order",
            "product",
            "quantity",
            "shipped_quantity",
            "created_date",
            "complete",
            "complete_date",
            "value",
            "shipped_value",
        ]
