from sqlalchemy import Column, Integer, String, Boolean

from airunner.components.data.models.base import BaseModel
from airunner.enums import (
    ImageGenerator,
    GeneratorSection,
    CanvasToolName,
    Mode,
    AvailableLanguage,
)


class ApplicationSettings(BaseModel):
    __tablename__ = "application_settings"
    id = Column(Integer, primary_key=True, autoincrement=True)
    use_cuda = Column(Boolean, default=True)
    sd_enabled = Column(Boolean, default=False)
    llm_enabled = Column(Boolean, default=False)
    tts_enabled = Column(Boolean, default=False)
    stt_enabled = Column(Boolean, default=False)
    controlnet_enabled = Column(Boolean, default=False)
    nsfw_filter = Column(Boolean, default=True)
    ai_mode = Column(Boolean, default=True)
    active_grid_size_lock = Column(Boolean, default=False)
    installation_path = Column(String, default="~/.local/share/airunner")
    current_layer_index = Column(Integer, default=0)
    paths_initialized = Column(Boolean, default=False)
    trust_remote_code = Column(
        Boolean, default=False
    )  # Leave this hardcoded. We will never trust remote code.
    resize_on_paste = Column(Boolean, default=True)
    image_to_new_layer = Column(Boolean, default=True)
    dark_mode_enabled = Column(Boolean, default=True)
    override_system_theme = Column(Boolean, default=True)
    latest_version_check = Column(Boolean, default=True)
    app_version = Column(String, default="")
    current_tool = Column(String, default=CanvasToolName.BRUSH.value)
    image_export_type = Column(String, default="png")
    auto_export_images = Column(Boolean, default=True)
    show_active_image_area = Column(Boolean, default=True)
    working_width = Column(Integer, default=1024)
    working_height = Column(Integer, default=1024)
    current_llm_generator = Column(String, default="causallm")
    current_image_generator = Column(String, default=ImageGenerator.FLUX.value)
    generator_section = Column(String, default=GeneratorSection.TXT2IMG.value)
    hf_api_key_read_key = Column(String, default="")
    hf_api_key_write_key = Column(String, default="")
    civit_ai_api_key = Column(String, default="")
    is_maximized = Column(Boolean, default=False)
    pivot_point_x = Column(Integer, default=0)
    pivot_point_y = Column(Integer, default=0)
    mode = Column(String, default=Mode.IMAGE.value)
    autoload_sd = Column(Boolean, default=True)
    autoload_llm = Column(Boolean, default=False)
    run_setup_wizard = Column(Boolean, default=True)
    download_wizard_completed = Column(Boolean, default=False)
    stable_diffusion_agreement_checked = Column(Boolean, default=True)
    airunner_agreement_checked = Column(Boolean, default=True)
    user_agreement_checked = Column(Boolean, default=True)
    age_agreement_checked = Column(Boolean, default=True)
    llama_license_agreement_checked = Column(Boolean, default=True)
    nodegraph_zoom = Column(Integer, default=0)
    nodegraph_center_x = Column(Integer, default=0)
    nodegraph_center_y = Column(Integer, default=0)
    detected_language = Column(String, default=AvailableLanguage.EN.value)
    use_detected_language = Column(Boolean, default=True)
    # Service settings
    run_in_background = Column(Boolean, default=False)
    start_at_login = Column(Boolean, default=False)
    http_server_enabled = Column(Boolean, default=True)
    http_server_host = Column(String, default="127.0.0.1")
    http_server_port = Column(Integer, default=5005)
    lna_enabled = Column(Boolean, default=False)
    # Knowledge migration
    knowledge_migrated = Column(Boolean, default=False)
