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

Base = declarative_base()


def get_current_user_id():
    return getpass.getuser()


class Historian(Base):
    __tablename__ = "Historian"

    NodeID = Column(String(36))
    ID = Column(Integer, primary_key=True)
    Acronym = Column(String(200), nullable=False)
    Name = Column(String(200))
    AssemblyName = Column(String)
    TypeName = Column(String)
    ConnectionString = Column(String)
    IsLocal = Column(Boolean)
    MeasurementReportingInterval = Column(Integer)
    Description = Column(String)
    LoadOrder = Column(Integer)
    Enabled = Column(Boolean)
    CreatedOn = Column(DateTime, default=func.now())
    CreatedBy = Column(String(200), default=get_current_user_id)
    UpdatedOn = Column(DateTime, default=func.now(), onupdate=func.now())
    UpdatedBy = Column(String(200), default=get_current_user_id, onupdate=get_current_user_id)
