# Path: il2fb/ds/airbridge/compat.py
# IS_WINDOWS = (sys.platform == "win32")
# 
# Path: il2fb/ds/airbridge/typing.py

# 
# Path: il2fb/ds/airbridge/dedicated_server/path.py
# def normalize_exe_path(initial: str) -> Path:
#     return Path(initial).resolve()
# 
# def normalize_config_path(root_dir: Path, initial: str=None) -> Path:
#     return normalize_file_path(
#         root_dir=root_dir,
#         initial=initial,
#         default_name=DEFAULT_CONFIG_NAME,
#     )
# 
# def normalize_start_script_path(root_dir: Path, initial: str=None) -> Path:
#     return normalize_file_path(
#         root_dir=root_dir,
#         initial=initial,
#         default_name=DEFAULT_START_SCRIPT_NAME,
#     )
# 
# Path: il2fb/ds/airbridge/dedicated_server/validators.py
# def validate_dedicated_server_file_access(file_path: StringOrPath) -> None:
#     if not os.access(file_path, os.F_OK):
#         raise FileNotFoundError(
#             f"file does not exist (path='{file_path}')"
#         )
# 
#     if not os.access(file_path, os.R_OK):
#         raise PermissionError(
#             f"file does not have read access (path='{file_path}')"
#         )
# 
# def validate_dedicated_server_config(config: ServerConfig) -> None:
#     if not config.console.connection.port:
#         raise ValueError(
#             "server's console is disabled, please enable it "
#             "(see: https://github.com/IL2HorusTeam/il2fb-ds-config#console-section)"
#         )
# 
#     if not config.device_link.connection.port:
#         raise ValueError(
#             "server's device link is disabled, please enable it "
#             "(see: https://github.com/IL2HorusTeam/il2fb-ds-config#devicelink-section)"
#         )


import asyncio
import configparser
import functools
import io
import logging
import psutil
from pathlib import Path
from typing import List, Awaitable, Optional
from il2fb.config.ds import ServerConfig
from il2fb.ds.airbridge.compat import IS_WINDOWS
from il2fb.ds.airbridge.typing import IntOrNone, StringHandler, StringList
from il2fb.ds.airbridge.dedicated_server.path import (
    normalize_exe_path, normalize_config_path, normalize_start_script_path,
)
from il2fb.ds.airbridge.dedicated_server.validators import (
    validate_dedicated_server_file_access, validate_dedicated_server_config,
)

    def __init__(
        self,
        loop: asyncio.AbstractEventLoop,
        exe_path: str,
        start_script_path: str=None,
        config_path: str=None,
        wine_bin_path: str=None,
        stdout_handler: StringHandler=None,
        stderr_handler: StringHandler=None,
        prompt_handler: StringHandler=None,
    ):
        self._loop = loop

        self.exe_path = normalize_exe_path(exe_path)
        validate_dedicated_server_file_access(self.exe_path)

        self.root_dir = self.exe_path.parent
        self.missions_dir = self.root_dir / "Missions"

        self.start_script_path = normalize_start_script_path(
            root_dir=self.root_dir,
            initial=start_script_path,
        )
        validate_dedicated_server_file_access(self.start_script_path)

        self.config_path = normalize_config_path(
            root_dir=self.root_dir,
            initial=config_path,
        )

# Path: il2fb/ds/airbridge/compat.py
# IS_WINDOWS = (sys.platform == "win32")
# 
# Path: il2fb/ds/airbridge/typing.py

# 
# Path: il2fb/ds/airbridge/dedicated_server/path.py
# def normalize_exe_path(initial: str) -> Path:
#     return Path(initial).resolve()
# 
# def normalize_config_path(root_dir: Path, initial: str=None) -> Path:
#     return normalize_file_path(
#         root_dir=root_dir,
#         initial=initial,
#         default_name=DEFAULT_CONFIG_NAME,
#     )
# 
# def normalize_start_script_path(root_dir: Path, initial: str=None) -> Path:
#     return normalize_file_path(
#         root_dir=root_dir,
#         initial=initial,
#         default_name=DEFAULT_START_SCRIPT_NAME,
#     )
# 
# Path: il2fb/ds/airbridge/dedicated_server/validators.py
# def validate_dedicated_server_file_access(file_path: StringOrPath) -> None:
#     if not os.access(file_path, os.F_OK):
#         raise FileNotFoundError(
#             f"file does not exist (path='{file_path}')"
#         )
# 
#     if not os.access(file_path, os.R_OK):
#         raise PermissionError(
#             f"file does not have read access (path='{file_path}')"
#         )
# 
# def validate_dedicated_server_config(config: ServerConfig) -> None:
#     if not config.console.connection.port:
#         raise ValueError(
#             "server's console is disabled, please enable it "
#             "(see: https://github.com/IL2HorusTeam/il2fb-ds-config#console-section)"
#         )
# 
#     if not config.device_link.connection.port:
#         raise ValueError(
#             "server's device link is disabled, please enable it "
#             "(see: https://github.com/IL2HorusTeam/il2fb-ds-config#devicelink-section)"
#         )


# Path: il2fb/ds/airbridge/dedicated_server/instance.py
import asyncio
import configparser
import functools
import io
import logging
import psutil
from pathlib import Path
from typing import List, Awaitable, Optional
from il2fb.config.ds import ServerConfig
from il2fb.ds.airbridge.compat import IS_WINDOWS
from il2fb.ds.airbridge.typing import IntOrNone, StringHandler, StringList
from il2fb.ds.airbridge.dedicated_server.path import (
    normalize_exe_path, normalize_config_path, normalize_start_script_path,
)
from il2fb.ds.airbridge.dedicated_server.validators import (
    validate_dedicated_server_file_access, validate_dedicated_server_config,
)


    def __init__(
        self,
        loop: asyncio.AbstractEventLoop,
        exe_path: str,
        start_script_path: str=None,
        config_path: str=None,
        wine_bin_path: str=None,
        stdout_handler: StringHandler=None,
        stderr_handler: StringHandler=None,
        prompt_handler: StringHandler=None,
    ):
        self._loop = loop

        self.exe_path = normalize_exe_path(exe_path)
        validate_dedicated_server_file_access(self.exe_path)

        self.root_dir = self.exe_path.parent
        self.missions_dir = self.root_dir / "Missions"

        self.start_script_path = normalize_start_script_path(
            root_dir=self.root_dir,
            initial=start_script_path,
        )
        validate_dedicated_server_file_access(self.start_script_path)

        self.config_path = normalize_config_path(
            root_dir=self.root_dir,
            initial=config_path,
        )

        validate_dedicated_server_file_access(self.start_script_path)