from rest_framework import serializers
from app.entities.models import Department, Delegation
from app.applicationlayer.utils import model_to_dict


class AdminDepartmentSerializer(serializers.ModelSerializer):

    def to_representation(self, instance):
        ret = super().to_representation(instance)
        ret['company'] = model_to_dict(instance.company)
        return ret

    class Meta:
        model = Department
        fields = '__all__'
        read_only_fields = (
            'created', 'createdby', 'modified', 'modifiedby', 'code',
        )

class DelegationSerializer(serializers.ModelSerializer):

    class Meta:
        model = Delegation
        fields = '__all__'
        read_only_fields = (
            'created', 'createdby', 'modified', 'modifiedby', 'code',
        )