"""
Order Items serializer
"""

from rest_framework import serializers

from core.apps.eggs import models
from core.apps.eggs.models import Group
from core.apps.eggs.serializers import courier_product, GroupSerializer


class OrderItemsSerializer(serializers.ModelSerializer):
    courier_product = courier_product.CourierProductSerializer(
        read_only=True, source="courier_product_id"
    )
    group = GroupSerializer(read_only=True, source="group_id")
    group_id = serializers.PrimaryKeyRelatedField(
        queryset=Group.objects.all(), required=True
    )

    class Meta:
        model = models.OrderItems
        fields = (
            "id",
            "group",
            "group_id",
            "count",
            "discount",
            "courier_product",
            "courier_product_id",
            "sale_type",
        )
        extra_kwargs = {"courier_product_id": {"write_only": True}}
