import sys

if sys.platform == "win32":
    import enum
    from _typeshed import Incomplete
    from collections.abc import Iterable, Iterator
    from signal import Signals
    from typing import Final, Literal, NamedTuple, TypedDict, overload, type_check_only

    from psutil import _psutil_windows
    from psutil._common import (
        ENCODING as ENCODING,
        AccessDenied as AccessDenied,
        NoSuchProcess as NoSuchProcess,
        TimeoutExpired as TimeoutExpired,
        conn_tmap as conn_tmap,
        conn_to_ntuple as conn_to_ntuple,
        debug as debug,
        isfile_strict as isfile_strict,
        memoize as memoize,
        memoize_when_activated as memoize_when_activated,
        parse_environ_block as parse_environ_block,
        usage_percent as usage_percent,
    )
    from psutil._psutil_windows import (
        ABOVE_NORMAL_PRIORITY_CLASS as ABOVE_NORMAL_PRIORITY_CLASS,
        BELOW_NORMAL_PRIORITY_CLASS as BELOW_NORMAL_PRIORITY_CLASS,
        HIGH_PRIORITY_CLASS as HIGH_PRIORITY_CLASS,
        IDLE_PRIORITY_CLASS as IDLE_PRIORITY_CLASS,
        NORMAL_PRIORITY_CLASS as NORMAL_PRIORITY_CLASS,
        REALTIME_PRIORITY_CLASS as REALTIME_PRIORITY_CLASS,
    )

    from . import _common

    __extra__all__: Final[list[str]]
    CONN_DELETE_TCB: Final = "DELETE_TCB"
    ERROR_PARTIAL_COPY: Final = 299
    PYPY: Final[bool]

    class AddressFamily(enum.IntEnum):
        AF_LINK = -1

    AF_LINK: Final = AddressFamily.AF_LINK
    TCP_STATUSES: Final[dict[int, str]]

    # These noqas workaround https://github.com/astral-sh/ruff/issues/10874
    class Priority(enum.IntEnum):
        ABOVE_NORMAL_PRIORITY_CLASS = _psutil_windows.ABOVE_NORMAL_PRIORITY_CLASS  # noqa: F811
        BELOW_NORMAL_PRIORITY_CLASS = _psutil_windows.BELOW_NORMAL_PRIORITY_CLASS  # noqa: F811
        HIGH_PRIORITY_CLASS = _psutil_windows.HIGH_PRIORITY_CLASS  # noqa: F811
        IDLE_PRIORITY_CLASS = _psutil_windows.IDLE_PRIORITY_CLASS  # noqa: F811
        NORMAL_PRIORITY_CLASS = _psutil_windows.NORMAL_PRIORITY_CLASS  # noqa: F811
        REALTIME_PRIORITY_CLASS = _psutil_windows.REALTIME_PRIORITY_CLASS  # noqa: F811

    class IOPriority(enum.IntEnum):
        IOPRIO_VERYLOW = 0
        IOPRIO_LOW = 1
        IOPRIO_NORMAL = 2
        IOPRIO_HIGH = 3

    IOPRIO_VERYLOW: Final = IOPriority.IOPRIO_VERYLOW
    IOPRIO_LOW: Final = IOPriority.IOPRIO_LOW
    IOPRIO_NORMAL: Final = IOPriority.IOPRIO_NORMAL
    IOPRIO_HIGH: Final = IOPriority.IOPRIO_HIGH

    pinfo_map: Final[dict[str, int]]

    class scputimes(NamedTuple):
        user: float
        system: float
        idle: float
        interrupt: float
        dpc: float

    class svmem(NamedTuple):
        total: int
        available: int
        percent: float
        used: int
        free: int

    class pmem(NamedTuple):
        rss: int
        vms: int
        num_page_faults: int
        peak_wset: int
        wset: int
        peak_paged_pool: int
        paged_pool: int
        peak_nonpaged_pool: int
        nonpaged_pool: int
        pagefile: int
        peak_pagefile: int
        private: int

    class pfullmem(NamedTuple):
        rss: int
        vms: int
        num_page_faults: int
        peak_wset: int
        wset: int
        peak_paged_pool: int
        paged_pool: int
        peak_nonpaged_pool: int
        nonpaged_pool: int
        pagefile: int
        peak_pagefile: int
        private: int
        uss: int

    class pmmap_grouped(NamedTuple):
        path: Incomplete
        rss: Incomplete

    class pmmap_ext(NamedTuple):
        addr: Incomplete
        perms: Incomplete
        path: Incomplete
        rss: Incomplete

    class pio(NamedTuple):
        read_count: int
        write_count: int
        read_bytes: int
        write_bytes: int
        other_count: int
        other_bytes: int

    def convert_dos_path(s: str) -> str: ...
    def getpagesize() -> int: ...
    def virtual_memory() -> svmem: ...
    def swap_memory() -> _common.sswap: ...

    disk_io_counters = _psutil_windows.disk_io_counters

    def disk_usage(path: str) -> _common.sdiskusage: ...
    def disk_partitions(all: bool) -> list[_common.sdiskpart]: ...
    def cpu_times() -> scputimes: ...
    def per_cpu_times() -> list[scputimes]: ...
    def cpu_count_logical() -> int | None: ...
    def cpu_count_cores() -> int | None: ...
    def cpu_stats() -> _common.scpustats: ...
    def cpu_freq() -> list[_common.scpufreq]: ...
    def getloadavg() -> tuple[float, float, float]: ...
    @overload
    def net_connections(kind: str, _pid: Literal[-1] = -1) -> list[_common.sconn]: ...
    @overload
    def net_connections(kind: str, _pid: int = -1) -> list[_common.pconn]: ...
    def net_if_stats() -> dict[str, _common.snicstats]: ...
    def net_io_counters() -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ...
    def net_if_addrs() -> list[tuple[str, int, str, str | None, None, None]]: ...
    def sensors_battery() -> _common.sbattery | None: ...
    def boot_time() -> float: ...
    def users() -> list[_common.suser]: ...
    def win_service_iter() -> Iterator[WindowsService]: ...
    def win_service_get(name: str) -> WindowsService: ...
    @type_check_only
    class _WindowsServiceAttrs(TypedDict):
        name: str
        display_name: str | None
        description: str
        binpath: str
        username: str
        start_type: str
        status: str
        pid: int | None

    class WindowsService:
        def __init__(self, name: str, display_name: str | None) -> None: ...
        def __eq__(self, other: object) -> bool: ...
        def __ne__(self, other: object) -> bool: ...
        def name(self) -> str: ...
        def display_name(self) -> str | None: ...
        def binpath(self) -> str: ...
        def username(self) -> str: ...
        def start_type(self) -> str: ...
        def pid(self) -> int: ...
        def status(self) -> str: ...
        def description(self) -> str: ...
        def as_dict(self) -> _WindowsServiceAttrs: ...

    pids = _psutil_windows.pids
    pid_exists = _psutil_windows.pid_exists
    ppid_map = _psutil_windows.ppid_map

    def is_permission_err(exc: OSError) -> bool: ...
    @overload
    def convert_oserror(exc: PermissionError, pid=None, name=None) -> AccessDenied: ...
    @overload
    def convert_oserror(exc: OSError, pid=None, name=None) -> AccessDenied | NoSuchProcess: ...
    def wrap_exceptions(fun): ...
    def retry_error_partial_copy(fun): ...

    class Process:
        __slots__ = ["_cache", "_name", "_ppid", "pid"]
        pid: int
        def __init__(self, pid: int) -> None: ...
        def oneshot_enter(self) -> None: ...
        def oneshot_exit(self) -> None: ...
        def name(self) -> str: ...
        def exe(self) -> str: ...
        def cmdline(self) -> list[str]: ...
        def environ(self) -> dict[str, str]: ...
        def ppid(self) -> int: ...
        def memory_info(self) -> pmem: ...
        def memory_full_info(self) -> pfullmem: ...
        def memory_maps(self) -> Iterator[tuple[str, str, str, int]]: ...
        def kill(self) -> None: ...
        def send_signal(self, sig: Literal[Signals.SIGTERM, Signals.CTRL_C_EVENT, Signals.CTRL_BREAK_EVENT]) -> None: ...
        def wait(self, timeout: float | None = None) -> int | None: ...
        def username(self) -> str: ...
        def create_time(self, fast_only: bool = False) -> float: ...
        def num_threads(self) -> int: ...
        def threads(self) -> list[_common.pthread]: ...
        def cpu_times(self) -> _common.pcputimes: ...
        def suspend(self) -> None: ...
        def resume(self) -> None: ...
        def cwd(self) -> str: ...
        def open_files(self) -> list[_common.popenfile]: ...
        def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ...
        def nice_get(self) -> Priority: ...
        def nice_set(self, value) -> None: ...
        def ionice_get(self) -> IOPriority: ...
        def ionice_set(self, ioclass: int, value: None) -> None: ...
        def io_counters(self) -> pio: ...
        def status(self) -> Literal["stopped", "running"]: ...
        def cpu_affinity_get(self) -> list[int]: ...
        def cpu_affinity_set(self, value: Iterable[int]) -> None: ...
        def num_handles(self) -> int: ...
        def num_ctx_switches(self) -> _common.pctxsw: ...
