import uuid

from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship as orm_relationship

from shared.database import BaseModel


class EmergencyContact(BaseModel):
    __tablename__ = "emergency_contacts"

    uuid = Column(UUID(as_uuid=True), default=uuid.uuid4, unique=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id"), index=True, nullable=False)
    name = Column(String(100), nullable=False)
    phone_number = Column(String(20), nullable=False)
    relation_type = Column(String(50))  # Переименовано из relationship в relation_type
    notes = Column(Text)
    
    # Отношение к пользователю (без back_populates для избежания циклических зависимостей)
    user = orm_relationship("User")