from . import db

class BairroZona(db.Model):
    __tablename__ = 'bairros_zonas'

    id = db.Column(db.Integer, primary_key=True)
    bairro = db.Column(db.String(100), unique=True, nullable=False)
    zona = db.Column(db.String(50), nullable=False)
    municipio = db.Column(db.String(100), nullable=False, default='Manaus')
    lat = db.Column(db.Float, nullable=True)
    lng = db.Column(db.Float, nullable=True)

    @classmethod
    def obter_zona_por_bairro(cls, bairro_nome):
        b_clean = bairro_nome.strip()
        reg = cls.query.filter(cls.bairro.ilike(f"%{b_clean}%")).first()
        if reg:
            return reg.zona, reg.lat, reg.lng
        return 'Zona Norte', -3.0305, -59.9708
