from rest_framework import serializers
from .models import Field, Note, Cost, Image, Job, Cultivation_calender, Product


class FieldSerializer(serializers.ModelSerializer):
    class Meta:
        model = Field
        fields = "__all__"


class NoteSerializer(serializers.ModelSerializer):
    class Meta:
        model = Note
        fields = "__all__"


class CostSerializer(serializers.ModelSerializer):
    class Meta:
        model = Cost
        fields = "__all__"


class ImageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Image
        fields = "__all__"


class JobSerializer(serializers.ModelSerializer):
    field = serializers.PrimaryKeyRelatedField(queryset=Field.objects.all())
    costs = serializers.PrimaryKeyRelatedField(
        queryset=Cost.objects.all(), required=False, allow_null=True
    )
    notes = serializers.PrimaryKeyRelatedField(
        queryset=Note.objects.all(), required=False, allow_null=True
    )
    images = serializers.PrimaryKeyRelatedField(
        queryset=Image.objects.all(), required=False, allow_null=True
    )

    class Meta:
        model = Job
        fields = "__all__"


class CultivationCalenderSerializer(serializers.ModelSerializer):
    class Meta:
        model = Cultivation_calender
        fields = "__all__"


class ProductSerializer(serializers.ModelSerializer):
    cultivation_calender = CultivationCalenderSerializer()

    class Meta:
        model = Product
        fields = "__all__"
