import typing, abc
from Microsoft.Win32.SafeHandles import SafePipeHandle
from System.IO import HandleInheritability, Stream, SeekOrigin
from System.Security.Principal import TokenImpersonationLevel, IdentityReference
from System.Threading.Tasks import Task, ValueTask_1, Task_1, ValueTask
from System.Threading import CancellationToken
from System import IAsyncResult, AsyncCallback, Array_1, Span_1, Memory_1, ReadOnlySpan_1, ReadOnlyMemory_1, MulticastDelegate
from System.Security.AccessControl import AccessRule, AccessControlType, InheritanceFlags, PropagationFlags, AuditRule, AuditFlags, NativeObjectSecurity
from System.Reflection import MethodInfo

class AnonymousPipeClientStream(PipeStream):
    @typing.overload
    def __init__(self, direction: PipeDirection, pipeHandleAsString: str) -> None: ...
    @typing.overload
    def __init__(self, direction: PipeDirection, safePipeHandle: SafePipeHandle) -> None: ...
    @typing.overload
    def __init__(self, pipeHandleAsString: str) -> None: ...
    @property
    def CanRead(self) -> bool: ...
    @property
    def CanSeek(self) -> bool: ...
    @property
    def CanTimeout(self) -> bool: ...
    @property
    def CanWrite(self) -> bool: ...
    @property
    def InBufferSize(self) -> int: ...
    @property
    def IsAsync(self) -> bool: ...
    @property
    def IsConnected(self) -> bool: ...
    @IsConnected.setter
    def IsConnected(self, value: bool) -> bool: ...
    @property
    def IsMessageComplete(self) -> bool: ...
    @property
    def Length(self) -> int: ...
    @property
    def OutBufferSize(self) -> int: ...
    @property
    def Position(self) -> int: ...
    @Position.setter
    def Position(self, value: int) -> int: ...
    @property
    def ReadMode(self) -> None: ...
    @ReadMode.setter
    def ReadMode(self, value: PipeTransmissionMode) -> None: ...
    @property
    def ReadTimeout(self) -> int: ...
    @ReadTimeout.setter
    def ReadTimeout(self, value: int) -> int: ...
    @property
    def SafePipeHandle(self) -> SafePipeHandle: ...
    @property
    def TransmissionMode(self) -> PipeTransmissionMode: ...
    @property
    def WriteTimeout(self) -> int: ...
    @WriteTimeout.setter
    def WriteTimeout(self, value: int) -> int: ...


class AnonymousPipeServerStream(PipeStream):
    @typing.overload
    def __init__(self) -> None: ...
    @typing.overload
    def __init__(self, direction: PipeDirection) -> None: ...
    @typing.overload
    def __init__(self, direction: PipeDirection, inheritability: HandleInheritability) -> None: ...
    @typing.overload
    def __init__(self, direction: PipeDirection, inheritability: HandleInheritability, bufferSize: int) -> None: ...
    @typing.overload
    def __init__(self, direction: PipeDirection, serverSafePipeHandle: SafePipeHandle, clientSafePipeHandle: SafePipeHandle) -> None: ...
    @property
    def CanRead(self) -> bool: ...
    @property
    def CanSeek(self) -> bool: ...
    @property
    def CanTimeout(self) -> bool: ...
    @property
    def CanWrite(self) -> bool: ...
    @property
    def ClientSafePipeHandle(self) -> SafePipeHandle: ...
    @property
    def InBufferSize(self) -> int: ...
    @property
    def IsAsync(self) -> bool: ...
    @property
    def IsConnected(self) -> bool: ...
    @IsConnected.setter
    def IsConnected(self, value: bool) -> bool: ...
    @property
    def IsMessageComplete(self) -> bool: ...
    @property
    def Length(self) -> int: ...
    @property
    def OutBufferSize(self) -> int: ...
    @property
    def Position(self) -> int: ...
    @Position.setter
    def Position(self, value: int) -> int: ...
    @property
    def ReadMode(self) -> None: ...
    @ReadMode.setter
    def ReadMode(self, value: PipeTransmissionMode) -> None: ...
    @property
    def ReadTimeout(self) -> int: ...
    @ReadTimeout.setter
    def ReadTimeout(self, value: int) -> int: ...
    @property
    def SafePipeHandle(self) -> SafePipeHandle: ...
    @property
    def TransmissionMode(self) -> PipeTransmissionMode: ...
    @property
    def WriteTimeout(self) -> int: ...
    @WriteTimeout.setter
    def WriteTimeout(self, value: int) -> int: ...
    def DisposeLocalCopyOfClientHandle(self) -> None: ...
    def GetClientHandleAsString(self) -> str: ...


class AnonymousPipeServerStreamAcl(abc.ABC):
    @staticmethod
    def Create(direction: PipeDirection, inheritability: HandleInheritability, bufferSize: int, pipeSecurity: PipeSecurity) -> AnonymousPipeServerStream: ...


class NamedPipeClientStream(PipeStream):
    @typing.overload
    def __init__(self, direction: PipeDirection, isAsync: bool, isConnected: bool, safePipeHandle: SafePipeHandle) -> None: ...
    @typing.overload
    def __init__(self, pipeName: str) -> None: ...
    @typing.overload
    def __init__(self, serverName: str, pipeName: str) -> None: ...
    @typing.overload
    def __init__(self, serverName: str, pipeName: str, direction: PipeDirection) -> None: ...
    @typing.overload
    def __init__(self, serverName: str, pipeName: str, direction: PipeDirection, options: PipeOptions) -> None: ...
    @typing.overload
    def __init__(self, serverName: str, pipeName: str, direction: PipeDirection, options: PipeOptions, impersonationLevel: TokenImpersonationLevel) -> None: ...
    @typing.overload
    def __init__(self, serverName: str, pipeName: str, direction: PipeDirection, options: PipeOptions, impersonationLevel: TokenImpersonationLevel, inheritability: HandleInheritability) -> None: ...
    @property
    def CanRead(self) -> bool: ...
    @property
    def CanSeek(self) -> bool: ...
    @property
    def CanTimeout(self) -> bool: ...
    @property
    def CanWrite(self) -> bool: ...
    @property
    def InBufferSize(self) -> int: ...
    @property
    def IsAsync(self) -> bool: ...
    @property
    def IsConnected(self) -> bool: ...
    @IsConnected.setter
    def IsConnected(self, value: bool) -> bool: ...
    @property
    def IsMessageComplete(self) -> bool: ...
    @property
    def Length(self) -> int: ...
    @property
    def NumberOfServerInstances(self) -> int: ...
    @property
    def OutBufferSize(self) -> int: ...
    @property
    def Position(self) -> int: ...
    @Position.setter
    def Position(self, value: int) -> int: ...
    @property
    def ReadMode(self) -> PipeTransmissionMode: ...
    @ReadMode.setter
    def ReadMode(self, value: PipeTransmissionMode) -> PipeTransmissionMode: ...
    @property
    def ReadTimeout(self) -> int: ...
    @ReadTimeout.setter
    def ReadTimeout(self, value: int) -> int: ...
    @property
    def SafePipeHandle(self) -> SafePipeHandle: ...
    @property
    def TransmissionMode(self) -> PipeTransmissionMode: ...
    @property
    def WriteTimeout(self) -> int: ...
    @WriteTimeout.setter
    def WriteTimeout(self, value: int) -> int: ...
    # Skipped Connect due to it being static, abstract and generic.

    Connect : Connect_MethodGroup
    class Connect_MethodGroup:
        @typing.overload
        def __call__(self) -> None:...
        @typing.overload
        def __call__(self, timeout: int) -> None:...

    # Skipped ConnectAsync due to it being static, abstract and generic.

    ConnectAsync : ConnectAsync_MethodGroup
    class ConnectAsync_MethodGroup:
        @typing.overload
        def __call__(self) -> Task:...
        @typing.overload
        def __call__(self, timeout: int) -> Task:...
        @typing.overload
        def __call__(self, cancellationToken: CancellationToken) -> Task:...
        @typing.overload
        def __call__(self, timeout: int, cancellationToken: CancellationToken) -> Task:...



class NamedPipeServerStream(PipeStream):
    @typing.overload
    def __init__(self, direction: PipeDirection, isAsync: bool, isConnected: bool, safePipeHandle: SafePipeHandle) -> None: ...
    @typing.overload
    def __init__(self, pipeName: str) -> None: ...
    @typing.overload
    def __init__(self, pipeName: str, direction: PipeDirection) -> None: ...
    @typing.overload
    def __init__(self, pipeName: str, direction: PipeDirection, maxNumberOfServerInstances: int) -> None: ...
    @typing.overload
    def __init__(self, pipeName: str, direction: PipeDirection, maxNumberOfServerInstances: int, transmissionMode: PipeTransmissionMode) -> None: ...
    @typing.overload
    def __init__(self, pipeName: str, direction: PipeDirection, maxNumberOfServerInstances: int, transmissionMode: PipeTransmissionMode, options: PipeOptions) -> None: ...
    @typing.overload
    def __init__(self, pipeName: str, direction: PipeDirection, maxNumberOfServerInstances: int, transmissionMode: PipeTransmissionMode, options: PipeOptions, inBufferSize: int, outBufferSize: int) -> None: ...
    MaxAllowedServerInstances : int
    @property
    def CanRead(self) -> bool: ...
    @property
    def CanSeek(self) -> bool: ...
    @property
    def CanTimeout(self) -> bool: ...
    @property
    def CanWrite(self) -> bool: ...
    @property
    def InBufferSize(self) -> int: ...
    @property
    def IsAsync(self) -> bool: ...
    @property
    def IsConnected(self) -> bool: ...
    @IsConnected.setter
    def IsConnected(self, value: bool) -> bool: ...
    @property
    def IsMessageComplete(self) -> bool: ...
    @property
    def Length(self) -> int: ...
    @property
    def OutBufferSize(self) -> int: ...
    @property
    def Position(self) -> int: ...
    @Position.setter
    def Position(self, value: int) -> int: ...
    @property
    def ReadMode(self) -> PipeTransmissionMode: ...
    @ReadMode.setter
    def ReadMode(self, value: PipeTransmissionMode) -> PipeTransmissionMode: ...
    @property
    def ReadTimeout(self) -> int: ...
    @ReadTimeout.setter
    def ReadTimeout(self, value: int) -> int: ...
    @property
    def SafePipeHandle(self) -> SafePipeHandle: ...
    @property
    def TransmissionMode(self) -> PipeTransmissionMode: ...
    @property
    def WriteTimeout(self) -> int: ...
    @WriteTimeout.setter
    def WriteTimeout(self, value: int) -> int: ...
    def BeginWaitForConnection(self, callback: AsyncCallback, state: typing.Any) -> IAsyncResult: ...
    def Disconnect(self) -> None: ...
    def EndWaitForConnection(self, asyncResult: IAsyncResult) -> None: ...
    def GetImpersonationUserName(self) -> str: ...
    def RunAsClient(self, impersonationWorker: PipeStreamImpersonationWorker) -> None: ...
    def WaitForConnection(self) -> None: ...
    # Skipped WaitForConnectionAsync due to it being static, abstract and generic.

    WaitForConnectionAsync : WaitForConnectionAsync_MethodGroup
    class WaitForConnectionAsync_MethodGroup:
        @typing.overload
        def __call__(self) -> Task:...
        @typing.overload
        def __call__(self, cancellationToken: CancellationToken) -> Task:...



class NamedPipeServerStreamAcl(abc.ABC):
    @staticmethod
    def Create(pipeName: str, direction: PipeDirection, maxNumberOfServerInstances: int, transmissionMode: PipeTransmissionMode, options: PipeOptions, inBufferSize: int, outBufferSize: int, pipeSecurity: PipeSecurity, inheritability: HandleInheritability = ..., additionalAccessRights: PipeAccessRights = ...) -> NamedPipeServerStream: ...


class PipeAccessRights(typing.SupportsInt):
    @typing.overload
    def __init__(self, value : int) -> None: ...
    @typing.overload
    def __init__(self, value : int, force_if_true: bool) -> None: ...
    def __int__(self) -> int: ...
    
    # Values:
    ReadData : PipeAccessRights # 1
    WriteData : PipeAccessRights # 2
    CreateNewInstance : PipeAccessRights # 4
    ReadExtendedAttributes : PipeAccessRights # 8
    WriteExtendedAttributes : PipeAccessRights # 16
    ReadAttributes : PipeAccessRights # 128
    WriteAttributes : PipeAccessRights # 256
    Write : PipeAccessRights # 274
    Delete : PipeAccessRights # 65536
    ReadPermissions : PipeAccessRights # 131072
    Read : PipeAccessRights # 131209
    ReadWrite : PipeAccessRights # 131483
    ChangePermissions : PipeAccessRights # 262144
    TakeOwnership : PipeAccessRights # 524288
    Synchronize : PipeAccessRights # 1048576
    FullControl : PipeAccessRights # 2032031
    AccessSystemSecurity : PipeAccessRights # 16777216


class PipeAccessRule(AccessRule):
    @typing.overload
    def __init__(self, identity: str, rights: PipeAccessRights, type: AccessControlType) -> None: ...
    @typing.overload
    def __init__(self, identity: IdentityReference, rights: PipeAccessRights, type: AccessControlType) -> None: ...
    @property
    def AccessControlType(self) -> AccessControlType: ...
    @property
    def IdentityReference(self) -> IdentityReference: ...
    @property
    def InheritanceFlags(self) -> InheritanceFlags: ...
    @property
    def IsInherited(self) -> bool: ...
    @property
    def PipeAccessRights(self) -> PipeAccessRights: ...
    @property
    def PropagationFlags(self) -> PropagationFlags: ...


class PipeAuditRule(AuditRule):
    @typing.overload
    def __init__(self, identity: IdentityReference, rights: PipeAccessRights, flags: AuditFlags) -> None: ...
    @typing.overload
    def __init__(self, identity: str, rights: PipeAccessRights, flags: AuditFlags) -> None: ...
    @property
    def AuditFlags(self) -> AuditFlags: ...
    @property
    def IdentityReference(self) -> IdentityReference: ...
    @property
    def InheritanceFlags(self) -> InheritanceFlags: ...
    @property
    def IsInherited(self) -> bool: ...
    @property
    def PipeAccessRights(self) -> PipeAccessRights: ...
    @property
    def PropagationFlags(self) -> PropagationFlags: ...


class PipeDirection(typing.SupportsInt):
    @typing.overload
    def __init__(self, value : int) -> None: ...
    @typing.overload
    def __init__(self, value : int, force_if_true: bool) -> None: ...
    def __int__(self) -> int: ...
    
    # Values:
    In : PipeDirection # 1
    Out : PipeDirection # 2
    InOut : PipeDirection # 3


class PipeOptions(typing.SupportsInt):
    @typing.overload
    def __init__(self, value : int) -> None: ...
    @typing.overload
    def __init__(self, value : int, force_if_true: bool) -> None: ...
    def __int__(self) -> int: ...
    
    # Values:
    None_ : PipeOptions # 0
    CurrentUserOnly : PipeOptions # 536870912
    Asynchronous : PipeOptions # 1073741824
    WriteThrough : PipeOptions # -2147483648


class PipesAclExtensions(abc.ABC):
    @staticmethod
    def GetAccessControl(stream: PipeStream) -> PipeSecurity: ...
    @staticmethod
    def SetAccessControl(stream: PipeStream, pipeSecurity: PipeSecurity) -> None: ...


class PipeSecurity(NativeObjectSecurity):
    def __init__(self) -> None: ...
    @property
    def AccessRightType(self) -> typing.Type[typing.Any]: ...
    @property
    def AccessRuleType(self) -> typing.Type[typing.Any]: ...
    @property
    def AreAccessRulesCanonical(self) -> bool: ...
    @property
    def AreAccessRulesProtected(self) -> bool: ...
    @property
    def AreAuditRulesCanonical(self) -> bool: ...
    @property
    def AreAuditRulesProtected(self) -> bool: ...
    @property
    def AuditRuleType(self) -> typing.Type[typing.Any]: ...
    def AccessRuleFactory(self, identityReference: IdentityReference, accessMask: int, isInherited: bool, inheritanceFlags: InheritanceFlags, propagationFlags: PropagationFlags, type: AccessControlType) -> AccessRule: ...
    def AddAccessRule(self, rule: PipeAccessRule) -> None: ...
    def AddAuditRule(self, rule: PipeAuditRule) -> None: ...
    def AuditRuleFactory(self, identityReference: IdentityReference, accessMask: int, isInherited: bool, inheritanceFlags: InheritanceFlags, propagationFlags: PropagationFlags, flags: AuditFlags) -> AuditRule: ...
    def RemoveAccessRule(self, rule: PipeAccessRule) -> bool: ...
    def RemoveAccessRuleSpecific(self, rule: PipeAccessRule) -> None: ...
    def RemoveAuditRule(self, rule: PipeAuditRule) -> bool: ...
    def RemoveAuditRuleAll(self, rule: PipeAuditRule) -> None: ...
    def RemoveAuditRuleSpecific(self, rule: PipeAuditRule) -> None: ...
    def ResetAccessRule(self, rule: PipeAccessRule) -> None: ...
    def SetAccessRule(self, rule: PipeAccessRule) -> None: ...
    def SetAuditRule(self, rule: PipeAuditRule) -> None: ...


class PipeStream(Stream):
    @property
    def CanRead(self) -> bool: ...
    @property
    def CanSeek(self) -> bool: ...
    @property
    def CanTimeout(self) -> bool: ...
    @property
    def CanWrite(self) -> bool: ...
    @property
    def InBufferSize(self) -> int: ...
    @property
    def IsAsync(self) -> bool: ...
    @property
    def IsConnected(self) -> bool: ...
    @IsConnected.setter
    def IsConnected(self, value: bool) -> bool: ...
    @property
    def IsMessageComplete(self) -> bool: ...
    @property
    def Length(self) -> int: ...
    @property
    def OutBufferSize(self) -> int: ...
    @property
    def Position(self) -> int: ...
    @Position.setter
    def Position(self, value: int) -> int: ...
    @property
    def ReadMode(self) -> PipeTransmissionMode: ...
    @ReadMode.setter
    def ReadMode(self, value: PipeTransmissionMode) -> PipeTransmissionMode: ...
    @property
    def ReadTimeout(self) -> int: ...
    @ReadTimeout.setter
    def ReadTimeout(self, value: int) -> int: ...
    @property
    def SafePipeHandle(self) -> SafePipeHandle: ...
    @property
    def TransmissionMode(self) -> PipeTransmissionMode: ...
    @property
    def WriteTimeout(self) -> int: ...
    @WriteTimeout.setter
    def WriteTimeout(self, value: int) -> int: ...
    def BeginRead(self, buffer: Array_1[int], offset: int, count: int, callback: AsyncCallback, state: typing.Any) -> IAsyncResult: ...
    def BeginWrite(self, buffer: Array_1[int], offset: int, count: int, callback: AsyncCallback, state: typing.Any) -> IAsyncResult: ...
    def EndRead(self, asyncResult: IAsyncResult) -> int: ...
    def EndWrite(self, asyncResult: IAsyncResult) -> None: ...
    def Flush(self) -> None: ...
    def ReadByte(self) -> int: ...
    def Seek(self, offset: int, origin: SeekOrigin) -> int: ...
    def SetLength(self, value: int) -> None: ...
    def WaitForPipeDrain(self) -> None: ...
    def WriteByte(self, value: int) -> None: ...
    # Skipped FlushAsync due to it being static, abstract and generic.

    FlushAsync : FlushAsync_MethodGroup
    class FlushAsync_MethodGroup:
        @typing.overload
        def __call__(self) -> Task:...
        @typing.overload
        def __call__(self, cancellationToken: CancellationToken) -> Task:...

    # Skipped Read due to it being static, abstract and generic.

    Read : Read_MethodGroup
    class Read_MethodGroup:
        @typing.overload
        def __call__(self, buffer: Span_1[int]) -> int:...
        @typing.overload
        def __call__(self, buffer: Array_1[int], offset: int, count: int) -> int:...

    # Skipped ReadAsync due to it being static, abstract and generic.

    ReadAsync : ReadAsync_MethodGroup
    class ReadAsync_MethodGroup:
        @typing.overload
        def __call__(self, buffer: Memory_1[int], cancellationToken: CancellationToken = ...) -> ValueTask_1[int]:...
        @typing.overload
        def __call__(self, buffer: Array_1[int], offset: int, count: int) -> Task_1[int]:...
        @typing.overload
        def __call__(self, buffer: Array_1[int], offset: int, count: int, cancellationToken: CancellationToken) -> Task_1[int]:...

    # Skipped Write due to it being static, abstract and generic.

    Write : Write_MethodGroup
    class Write_MethodGroup:
        @typing.overload
        def __call__(self, buffer: ReadOnlySpan_1[int]) -> None:...
        @typing.overload
        def __call__(self, buffer: Array_1[int], offset: int, count: int) -> None:...

    # Skipped WriteAsync due to it being static, abstract and generic.

    WriteAsync : WriteAsync_MethodGroup
    class WriteAsync_MethodGroup:
        @typing.overload
        def __call__(self, buffer: ReadOnlyMemory_1[int], cancellationToken: CancellationToken = ...) -> ValueTask:...
        @typing.overload
        def __call__(self, buffer: Array_1[int], offset: int, count: int) -> Task:...
        @typing.overload
        def __call__(self, buffer: Array_1[int], offset: int, count: int, cancellationToken: CancellationToken) -> Task:...



class PipeStreamImpersonationWorker(MulticastDelegate):
    def __init__(self, object: typing.Any, method: int) -> None: ...
    @property
    def Method(self) -> MethodInfo: ...
    @property
    def Target(self) -> typing.Any: ...
    def BeginInvoke(self, callback: AsyncCallback, object: typing.Any) -> IAsyncResult: ...
    def EndInvoke(self, result: IAsyncResult) -> None: ...
    def Invoke(self) -> None: ...


class PipeTransmissionMode(typing.SupportsInt):
    @typing.overload
    def __init__(self, value : int) -> None: ...
    @typing.overload
    def __init__(self, value : int, force_if_true: bool) -> None: ...
    def __int__(self) -> int: ...
    
    # Values:
    Byte : PipeTransmissionMode # 0
    Message : PipeTransmissionMode # 1

