from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

from models.entities.base import Base

class Celula(Base):
    __tablename__ = 'celulas'
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    nome = Column(String(100), nullable=False)
    setor_id = Column(Integer, ForeignKey('setores.id', use_alter=True, name='fk_celula_setor'))
    cr_id = Column(Integer, ForeignKey('comites_regionais.id', use_alter=True, name='fk_celula_cr'))
    secretario = Column(Integer, ForeignKey('militantes.id', use_alter=True, name='fk_celula_secretario'))
    responsavel_financas = Column(Integer, ForeignKey('militantes.id', use_alter=True, name='fk_celula_responsavel_financas'))
    quadro_orientador = Column(String(255))
    
    # Relacionamentos
    setor = relationship("Setor", back_populates="celulas")
    cr = relationship("ComiteRegional", back_populates="celulas")
    militantes = relationship("Militante", back_populates="celula", foreign_keys="[Militante.celula_id]")
    secretario_rel = relationship("Militante", foreign_keys=[secretario])
    responsavel_financas_rel = relationship("Militante", foreign_keys=[responsavel_financas])
    pagamentos = relationship("PagamentoCelula", back_populates="celula")
    usuarios = relationship("Usuario", back_populates="celula")