"""
Agent Models
"""
from sqlalchemy import Column, Integer, String, Text, DateTime
from sqlalchemy.sql import func
from app.core.database import Base


class AgentsAccess(Base):
    """Agents access table"""
    __tablename__ = "agents_access"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    agent_id = Column(Text, nullable=False)
    agent_name = Column(Text, nullable=False)
    access_key = Column(Text, nullable=False)
    license_number = Column(Text, nullable=False)
    license_count = Column(Text, nullable=False)
    remain_license_count = Column(Text, nullable=False)
    start_date = Column(Text, nullable=False)
    end_date = Column(Text)
    active = Column(Integer, default=1)
    created_at = Column(Text)
    updated_at = Column(Text)


class AccessManage(Base):
    """Access management table"""
    __tablename__ = "access_manage"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    user_id = Column(Text, nullable=False)
    user_name = Column(Text, nullable=False)
    agent_id = Column(Text, nullable=False)
    agent_name = Column(Text, nullable=False)
    license_number = Column(Text, nullable=False)
    start_date = Column(Text, nullable=False)
    end_date = Column(Text, nullable=False)
    created_at = Column(Text)
    updated_at = Column(Text)


class AgentManagement(Base):
    """Agent management table"""
    __tablename__ = "agent_management"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    agent_id = Column(Text, nullable=False, unique=True)
    agent_name = Column(Text, nullable=False, unique=True)
    agent_access = Column(Text, nullable=False, unique=True)
    init_training_data = Column(Text, nullable=False)
    endpoint = Column(Text, nullable=False)
    admin_id = Column(Text, nullable=False)
    max_row_count = Column(Text)
    extra1 = Column(Text, nullable=False)
    extra2 = Column(Text, nullable=False)
    database = Column(Text, nullable=False)
    api = Column(Text, nullable=False)
    file = Column(Text, nullable=False)
    data_source_type = Column(Text, nullable=False)
    default_data_source_type = Column(Text, nullable=False)
    db_type = Column(Text, nullable=False)
    host = Column(Text, nullable=False)
    port = Column(Text, nullable=False)
    username = Column(Text, nullable=False)
    password = Column(Text, nullable=False)
    db_name = Column(Text, nullable=False)
    connection = Column(Text, nullable=False)
    description = Column(Text, nullable=True)
    created_at = Column(Text, nullable=False)
    updated_at = Column(Text, nullable=False)


class AgentAdmin(Base):
    """Agent admin table"""
    __tablename__ = "agent_admin"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    agent_id = Column(Text, nullable=False)
    agent_name = Column(Text, nullable=False)
    admin_id = Column(Text, nullable=False)
    admin_name = Column(Text, nullable=False)
    created_at = Column(Text, nullable=False)
    updated_at = Column(Text, nullable=False)


class Training(Base):
    """Training table"""
    __tablename__ = "training"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    agent_id = Column(Text, nullable=False)
    name = Column(Text, nullable=False, unique=True)
    endpoint = Column(Text, nullable=False)
    base_params = Column(Text, nullable=False)
    response_schema = Column(Text, nullable=False)
    description = Column(Text)
    extra1 = Column(Text, nullable=False)
    extra2 = Column(Text, nullable=False)
    created_at = Column(Text, nullable=False)
    updated_at = Column (Text, nullable=False)
