import getpass
from sqlalchemy import Column, Integer, String, Boolean, DateTime
from sqlalchemy.orm import declarative_base
from sqlalchemy.sql import func
import uuid

Base = declarative_base()


def get_current_user_id():
    return getpass.getuser()


class CustomFilterAdapter(Base):
    __tablename__ = "CustomFilterAdapter"

    NodeID = Column(String(36), default=lambda: str(uuid.uuid4()))
    ID = Column(Integer, primary_key=True, autoincrement=True)
    AdapterName = Column(String(200), nullable=False)
    AssemblyName = Column(String, nullable=False, default="DynamicCalculator.dll")
    TypeName = Column(String, nullable=False, default="DynamicCalculator.DynamicFilter")
    ConnectionString = Column(String)
    LoadOrder = Column(Integer, default=0)
    Enabled = Column(Boolean, default=True)
    CreatedOn = Column(DateTime, default=func.now())
    CreatedBy = Column(String(200), nullable=False, default=get_current_user_id)
    UpdatedOn = Column(DateTime, default=func.now(), onupdate=func.now())
    UpdatedBy = Column(String(200), nullable=False, default=get_current_user_id, onupdate=get_current_user_id)
