from datetime import datetime
from typing import Optional

from pydantic import BaseModel
from sqlalchemy import Column, Integer, String, DateTime, Table, ForeignKey, UniqueConstraint
from app.models.base_model import Base



class SystemDataModel(Base):
    __tablename__ = 'system_data'
    id = Column(Integer, primary_key=True, index=True)
    title = Column(String(255))
    desc = Column(String(1000))
    version = Column(String(32))
    machine_id = Column(String(255))
    license_code = Column(String(1000))
    status = Column(Integer, default=0)
    expired_at = Column(DateTime)
    created_at = Column(DateTime, default=datetime.now())
    updated_at = Column(DateTime, default=datetime.now(), onupdate=datetime.now())


    def to_dict(self):
        return {
            # 'id': self.id,
            'title': self.title,
            'desc': self.desc,
            'version': self.version,
            'machine_id': self.machine_id,
            'license_code': self.license_code,
            'status': self.status,
            'expired_at': self.expired_at.strftime('%Y-%m-%d %H:%M') if self.expired_at else '',
        }

    def __repr__(self):
        return '<Role name:%r description:%r iconCls:%r seq:%r>\n' \
            % (self.NAME, self.DESCRIPTION, self.ICONCLS, self.SEQ)


class SystemData(BaseModel):
    title: str
    desc: str
    logo: str

class SystemLicense(BaseModel):
    licenseCode: str

