from rest_framework import serializers

from .models import Contract, Customer, Order

from apps.mtm.serializers import MaterialSimpleSerializer

class CustomerSerializer(serializers.ModelSerializer):
    class Meta:
        model = Customer
        fields = '__all__'

class CustomerCreateUpdateSerializer(serializers.ModelSerializer):
    class Meta:
        model = Customer
        fields = ['name', 'address', 'contact', 'contact_phone', 'description']

class CustomerSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Customer
        fields = ['id', 'name']

class ContractSerializer(serializers.ModelSerializer):
    customer_  = CustomerSimpleSerializer(source='customer', read_only=True)
    class Meta:
        model = Contract
        fields = '__all__'

class ContractSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Contract
        fields = ['id', 'name', 'number']

class ContractCreateUpdateSerializer(serializers.ModelSerializer):
    class Meta:
        model = Contract
        fields = ['name', 'number', 'amount', 'customer', 'sign_date', 'description']


class OrderCreateUpdateSerializer(serializers.ModelSerializer):
    class Meta:
        model = Order
        fields = ['number', 'customer', 'contract', 'product', 'count', 'delivery_date']

class OrderSerializer(serializers.ModelSerializer):
    contract_ =  ContractSimpleSerializer(source='contract', read_only=True)
    customer_  = CustomerSimpleSerializer(source='customer', read_only=True)
    product_  = MaterialSimpleSerializer(source='product', read_only=True)
    class Meta:
        model = Order
        fields = '__all__'
