"""JSON schemas and utilities for workflow settings"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/settings/schemas.ipynb.

# %% auto 0
__all__ = ['WORKFLOW_SETTINGS_SCHEMA', 'get_settings_from_config']

# %% ../../nbs/settings/schemas.ipynb 3
from typing import Dict, Any, List

from ..core.config import SingleFileWorkflowConfig
from ..media.config import MEDIA_CONFIG_SCHEMA
from ..storage.config import STORAGE_CONFIG_SCHEMA

# %% ../../nbs/settings/schemas.ipynb 5
WORKFLOW_SETTINGS_SCHEMA = {
    "name": "single_file_workflow",
    "title": "Single File Transcription Settings",
    "description": "Configure media scanning, storage, and workflow behavior",
    "type": "object",
    "properties": {
        # Media settings
        "media_directories": {
            "type": "array",
            "title": "Media Directories",
            "description": "Directories to scan for media files",
            "items": {"type": "string"},
            "default": []
        },
        "scan_audio": {
            "type": "boolean",
            "title": "Scan Audio Files",
            "description": "Include audio files in scan results",
            "default": True
        },
        "scan_video": {
            "type": "boolean",
            "title": "Scan Video Files",
            "description": "Include video files in scan results",
            "default": True
        },
        "recursive_scan": {
            "type": "boolean",
            "title": "Recursive Scan",
            "description": "Scan subdirectories",
            "default": True
        },
        "items_per_page": {
            "type": "integer",
            "title": "Items Per Page",
            "description": "Number of files to show per page",
            "default": 30,
            "minimum": 10,
            "maximum": 100
        },
        "default_view": {
            "type": "string",
            "title": "Default View",
            "description": "Default view mode for file selection (currently only list/table view is implemented)",
            "enum": ["list"],
            "default": "list"
        },

        # Storage settings
        "auto_save": {
            "type": "boolean",
            "title": "Auto-save Results",
            "description": "Automatically save transcription results when complete",
            "default": True
        },
        "results_directory": {
            "type": "string",
            "title": "Results Directory",
            "description": "Directory to save transcription results",
            "default": "transcription_results"
        },

        # Resource management settings
        "gpu_memory_threshold_percent": {
            "type": "number",
            "title": "GPU Memory Threshold (%)",
            "description": "GPU memory usage threshold for conflict detection (0-100)",
            "default": 45.0,
            "minimum": 0,
            "maximum": 100
        }
    }
}

# %% ../../nbs/settings/schemas.ipynb 7
def get_settings_from_config(
    media_config,                            # MediaConfig instance with media scanning settings
    storage_config,                          # StorageConfig instance with result storage settings
    workflow_config=None                     # Optional SingleFileWorkflowConfig for additional settings
) -> dict:                                   # Dictionary of current settings values
    """Extract settings values from config objects."""
    settings = {
        # Media settings
        "media_directories": media_config.directories,
        "scan_audio": media_config.scan_audio,
        "scan_video": media_config.scan_video,
        "recursive_scan": media_config.recursive_scan,
        "items_per_page": media_config.items_per_page,
        "default_view": media_config.default_view,

        # Storage settings
        "auto_save": storage_config.auto_save,
        "results_directory": storage_config.results_directory,
    }

    # Add workflow-level settings if provided
    if workflow_config:
        settings["gpu_memory_threshold_percent"] = workflow_config.gpu_memory_threshold_percent

    return settings
