from rest_framework import serializers
from .models import Establishment, EstablishmentType

class EstablishmentTypeSerializer(serializers.ModelSerializer):
    class Meta:
        model = EstablishmentType
        fields = ['id', 'name', 'code']


class EstablishmentSerializer(serializers.ModelSerializer):
    location_name = serializers.CharField(source='location.name', read_only=True)
    area_name = serializers.CharField(source='location.area.name', read_only=True)
    locality_name = serializers.CharField(source='location.area.locality.name', read_only=True)
    state_name = serializers.CharField(source='location.area.locality.state.name', read_only=True)
    establishment_type_name = serializers.CharField(source='establishment_type.name', read_only=True)

    class Meta:
        model = Establishment
        fields = [
            'id', 'name_ar', 'name_en', 'establishment_type', 'establishment_type_name',
            'location', 'location_name', 'area_name', 'locality_name', 'state_name',
            'license_number', 'owner_name', 'phone', 'address',
            'created_at', 'updated_at'
        ]
        read_only_fields = ['id', 'created_at', 'updated_at']