from rest_framework import serializers

from LiveStock.Cooperative.serializers import CooperativeSerializer, CooperativeForSharesSerializer
from LiveStock.Union.serializers import UnionSerializer
from LiveStock.models import LiveStockProvinceJahad, LiveStockRolseProduct, LiveStockAllocations, LiveStockProduct, \
    CooperativeProductsShare
from authentication.serializer.serializer import BankCardSerializer, SystemUserProfileForInspectionSerializer
from authentication.serializers import SystemAddressSerializer
from ticket.serializers import SystemUserProfileForTicketPermissionSerializer


class LiveStockProvinceJahadSerializer(serializers.ModelSerializer):
    user = SystemUserProfileForInspectionSerializer(read_only=True)
    address = SystemAddressSerializer(read_only=True)
    user_bank_info = BankCardSerializer(required=False)

    class Meta:
        model = LiveStockProvinceJahad
        fields = '__all__'


class LiveStockProductSerializer(serializers.ModelSerializer):
    class Meta:
        model = LiveStockProduct
        fields = '__all__'


class LiveStockRolseProductSerializer(serializers.ModelSerializer):
    parent_product = LiveStockProductSerializer(read_only=True)

    class Meta:
        model = LiveStockRolseProduct
        fields = '__all__'


class LiveStockAllocationsSerializer(serializers.ModelSerializer):
    product = LiveStockRolseProductSerializer(read_only=True)
    union = UnionSerializer(read_only=True)
    cooperative = CooperativeSerializer(read_only=True)
    jahad = LiveStockProvinceJahadSerializer(read_only=True)

    class Meta:
        model = LiveStockAllocations
        fields = '__all__'


class CooperativeProductsShareSerializer(serializers.ModelSerializer):
    cooperative = CooperativeForSharesSerializer(read_only=True)
    product = LiveStockRolseProductSerializer(read_only=True)


    class Meta:
        model = CooperativeProductsShare
        fields = '__all__'
