from datetime import datetime
from . import db

class Politico(db.Model):
    __tablename__ = 'politicos'

    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.String(150), nullable=False)
    cargo = db.Column(db.String(100), nullable=True)
    partido = db.Column(db.String(100), nullable=True)
    foto_url = db.Column(db.String(255), nullable=True)
    criado_em = db.Column(db.DateTime, default=datetime.utcnow)

    campanha_vinculos = db.relationship('CampanhaPolitico', backref='politico', lazy=True, cascade="all, delete-orphan")


class CampanhaPolitico(db.Model):
    __tablename__ = 'campanha_politicos'

    REL_PRINCIPAL = 'principal'
    REL_ALIADO = 'aliado'
    REL_CONCORRENTE = 'concorrente'
    REL_COORDENADOR = 'coordenador'

    id = db.Column(db.Integer, primary_key=True)
    campanha_id = db.Column(db.Integer, db.ForeignKey('campanhas.id'), nullable=False)
    politico_id = db.Column(db.Integer, db.ForeignKey('politicos.id'), nullable=False)
    relacao = db.Column(db.String(50), nullable=False, default=REL_ALIADO)
