# 📄 models.py
from sqlalchemy import Column, String, Integer, Float, DateTime, Text
from sqlalchemy.dialects.postgresql import UUID
import uuid
from datetime import datetime
from database import Base

class ParametrosFormula(Base):
    __tablename__ = 'parametros_formula'
    __table_args__ = {'schema': 'faturas', 'extend_existing': True}

    id = Column(Integer, primary_key=True, autoincrement=True)
    nome = Column(String)
    formula = Column(Text)


class Fatura(Base):
    __tablename__ = "faturas"
    __table_args__ = {'schema': 'faturas'}

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    nome = Column(String)
    classificacao_tarifaria = Column("classificacao_tarifaria", String)
    unidade_consumidora = Column("unidade_consumidora", String)
    referencia = Column(String)
    valor_total = Column(Float)

    pis_aliq = Column("pis_aliq", Float)
    pis_valor = Column("pis_valor", Float)
    pis_base = Column("pis_base", Float)

    icms_aliq = Column("icms_aliq", Float)
    icms_valor = Column("icms_valor", Float)
    icms_base = Column("icms_base", Float)

    cofins_aliq = Column("cofins_aliq", Float)
    cofins_valor = Column("cofins_valor", Float)
    cofins_base = Column("cofins_base", Float)

    consumo = Column("consumo", Float)
    tarifa = Column("tarifa", Float)

    nota_fiscal = Column(String)
    data_processamento = Column(DateTime, default=datetime.utcnow)
    arquivo_pdf = Column("arquivo_pdf", String)
    cidade = Column(String)
    estado = Column(String)
    distribuidora = Column(String)
    link_arquivo = Column("link_arquivo", String)


class LogProcessamento(Base):
    __tablename__ = "logs_processamento"
    __table_args__ = {'schema': 'faturas'}

    id = Column(Integer, primary_key=True, autoincrement=True)
    nome_arquivo = Column(String)
    status = Column(String)
    mensagem = Column(Text)
    acao = Column(String)  # nova coluna existente no banco
    data_log = Column("data_log", DateTime, default=datetime.utcnow)


class AliquotaUF(Base):
    __tablename__ = "aliquotas_uf"
    __table_args__ = {'schema': 'faturas'}

    id = Column(Integer, primary_key=True, autoincrement=True)
    uf = Column(String)
    exercicio = Column(String)
    aliquota = Column(Float)

class SelicMensal(Base):
    __tablename__ = "selic_mensal"
    __table_args__ = {'schema': 'faturas'}

    id = Column(Integer, primary_key=True, autoincrement=True)
    ano = Column(Integer)
    mes = Column(Integer)
    fator = Column(Float)
