using System;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Ncm;
using LibHac.Sf;
using LibHac.Spl;
using IFileSystemSf = LibHac.FsSrv.Sf.IFileSystem;
using IFileSf = LibHac.FsSrv.Sf.IFile;
using IStorageSf = LibHac.FsSrv.Sf.IStorage;

namespace LibHac.FsSrv.Sf;

public interface IFileSystemProxy : IDisposable
{
    Result SetCurrentProcess(ulong processId);
    Result OpenDataFileSystemByCurrentProcess(ref SharedRef<IFileSystemSf> outFileSystem);
    Result OpenFileSystemWithPatch(ref SharedRef<IFileSystemSf> outFileSystem, ProgramId programId, FileSystemProxyType fsType);
    Result OpenFileSystemWithId(ref SharedRef<IFileSystemSf> outFileSystem, in FspPath path, ulong id, FileSystemProxyType fsType);
    Result OpenDataFileSystemByProgramId(ref SharedRef<IFileSystemSf> outFileSystem, ProgramId programId);
    Result OpenBisFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, in FspPath rootPath, BisPartitionId partitionId);
    Result OpenBisStorage(ref SharedRef<IStorageSf> outStorage, BisPartitionId partitionId);
    Result InvalidateBisCache();
    Result OpenHostFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, in FspPath path);
    Result OpenSdCardFileSystem(ref SharedRef<IFileSystemSf> outFileSystem);
    Result FormatSdCardFileSystem();
    Result DeleteSaveDataFileSystem(ulong saveDataId);
    Result CreateSaveDataFileSystem(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo, in SaveDataMetaInfo metaInfo);
    Result CreateSaveDataFileSystemBySystemSaveDataId(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo);
    Result RegisterSaveDataFileSystemAtomicDeletion(InBuffer saveDataIds);
    Result DeleteSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId);
    Result FormatSdCardDryRun();
    Result IsExFatSupported(out bool isSupported);
    Result DeleteSaveDataFileSystemBySaveDataAttribute(SaveDataSpaceId spaceId, in SaveDataAttribute attribute);
    Result OpenGameCardStorage(ref SharedRef<IStorageSf> outStorage, GameCardHandle handle, GameCardPartitionRaw partitionId);
    Result OpenGameCardFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, GameCardHandle handle, GameCardPartition partitionId);
    Result ExtendSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, long dataSize, long journalSize);
    Result DeleteCacheStorage(ushort index);
    Result GetCacheStorageSize(out long dataSize, out long journalSize, ushort index);
    Result CreateSaveDataFileSystemWithHashSalt(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo, in SaveDataMetaInfo metaInfo, in HashSalt hashSalt);
    Result OpenHostFileSystemWithOption(ref SharedRef<IFileSystemSf> outFileSystem, in FspPath path, MountHostOption option);
    Result OpenSaveDataFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute);
    Result OpenSaveDataFileSystemBySystemSaveDataId(ref SharedRef<IFileSystemSf> outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute);
    Result OpenReadOnlySaveDataFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute);
    Result ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(OutBuffer extraDataBuffer, SaveDataSpaceId spaceId, ulong saveDataId);
    Result ReadSaveDataFileSystemExtraData(OutBuffer extraDataBuffer, ulong saveDataId);
    Result WriteSaveDataFileSystemExtraData(ulong saveDataId, SaveDataSpaceId spaceId, InBuffer extraDataBuffer);
    Result OpenSaveDataInfoReader(ref SharedRef<ISaveDataInfoReader> outInfoReader);
    Result OpenSaveDataInfoReaderBySaveDataSpaceId(ref SharedRef<ISaveDataInfoReader> outInfoReader, SaveDataSpaceId spaceId);
    Result OpenSaveDataInfoReaderOnlyCacheStorage(ref SharedRef<ISaveDataInfoReader> outInfoReader);
    Result OpenSaveDataInternalStorageFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, SaveDataSpaceId spaceId, ulong saveDataId);
    Result UpdateSaveDataMacForDebug(SaveDataSpaceId spaceId, ulong saveDataId);
    Result WriteSaveDataFileSystemExtraDataWithMask(ulong saveDataId, SaveDataSpaceId spaceId, InBuffer extraDataBuffer, InBuffer maskBuffer);
    Result FindSaveDataWithFilter(out long count, OutBuffer saveDataInfoBuffer, SaveDataSpaceId spaceId, in SaveDataFilter filter);
    Result OpenSaveDataInfoReaderWithFilter(ref SharedRef<ISaveDataInfoReader> outInfoReader, SaveDataSpaceId spaceId, in SaveDataFilter filter);
    Result ReadSaveDataFileSystemExtraDataBySaveDataAttribute(OutBuffer extraDataBuffer, SaveDataSpaceId spaceId, in SaveDataAttribute attribute);
    Result WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(in SaveDataAttribute attribute, SaveDataSpaceId spaceId, InBuffer extraDataBuffer, InBuffer maskBuffer);
    Result ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(OutBuffer extraDataBuffer, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, InBuffer maskBuffer);
    Result OpenSaveDataMetaFile(ref SharedRef<IFileSf> outFile, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, SaveDataMetaType type);
    Result OpenSaveDataTransferManager(ref SharedRef<ISaveDataTransferManager> outTransferManager);
    Result OpenSaveDataTransferManagerVersion2(ref SharedRef<ISaveDataTransferManagerWithDivision> outTransferManager);
    Result OpenSaveDataTransferProhibiter(ref SharedRef<ISaveDataTransferProhibiter> outProhibiter, Ncm.ApplicationId applicationId);
    Result ListAccessibleSaveDataOwnerId(out int readCount, OutBuffer idBuffer, ProgramId programId, int startIndex, int bufferIdCount);
    Result OpenSaveDataTransferManagerForSaveDataRepair(ref SharedRef<ISaveDataTransferManagerForSaveDataRepair> outTransferManager);
    Result OpenSaveDataMover(ref SharedRef<ISaveDataMover> outSaveDataMover, SaveDataSpaceId sourceSpaceId, SaveDataSpaceId destinationSpaceId, NativeHandle workBufferHandle, ulong workBufferSize);
    Result OpenSaveDataTransferManagerForRepair(ref SharedRef<ISaveDataTransferManagerForRepair> outTransferManager);
    Result OpenImageDirectoryFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, ImageDirectoryId directoryId);
    Result OpenBaseFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, BaseFileSystemId fileSystemId);
    Result FormatBaseFileSystem(BaseFileSystemId fileSystemId);
    Result OpenContentStorageFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, ContentStorageId storageId);
    Result OpenCloudBackupWorkStorageFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, CloudBackupWorkStorageId storageId);
    Result OpenCustomStorageFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, CustomStorageId storageId);
    Result OpenDataStorageByCurrentProcess(ref SharedRef<IStorageSf> outStorage);
    Result OpenDataStorageByProgramId(ref SharedRef<IStorageSf> outStorage, ProgramId programId);
    Result OpenDataStorageByDataId(ref SharedRef<IStorageSf> outStorage, DataId dataId, StorageId storageId);
    Result OpenPatchDataStorageByCurrentProcess(ref SharedRef<IStorageSf> outStorage);
    Result OpenDataFileSystemWithProgramIndex(ref SharedRef<IFileSystemSf> outFileSystem, byte programIndex);
    Result OpenDataStorageWithProgramIndex(ref SharedRef<IStorageSf> outStorage, byte programIndex);
    Result OpenDeviceOperator(ref SharedRef<IDeviceOperator> outDeviceOperator);
    Result OpenSdCardDetectionEventNotifier(ref SharedRef<IEventNotifier> outEventNotifier);
    Result OpenGameCardDetectionEventNotifier(ref SharedRef<IEventNotifier> outEventNotifier);
    Result OpenSystemDataUpdateEventNotifier(ref SharedRef<IEventNotifier> outEventNotifier);
    Result NotifySystemDataUpdateEvent();
    Result SimulateDeviceDetectionEvent(SdmmcPort port, SimulatingDeviceDetectionMode mode, bool signalEvent);
    Result QuerySaveDataTotalSize(out long totalSize, long dataSize, long journalSize);
    Result VerifySaveDataFileSystem(ulong saveDataId, OutBuffer readBuffer);
    Result CorruptSaveDataFileSystem(ulong saveDataId);
    Result CreatePaddingFile(long size);
    Result DeleteAllPaddingFiles();
    Result GetRightsId(out RightsId rightsId, ProgramId programId, StorageId storageId);
    Result RegisterExternalKey(in RightsId rightsId, in AccessKey externalKey);
    Result UnregisterAllExternalKey();
    Result GetRightsIdByPath(out RightsId rightsId, in FspPath path);
    Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in FspPath path);
    Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference);
    Result GetFreeSpaceSizeForSaveData(out long freeSpaceSize, SaveDataSpaceId spaceId);
    Result VerifySaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId, OutBuffer readBuffer);
    Result CorruptSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId);
    Result QuerySaveDataInternalStorageTotalSize(out long size, SaveDataSpaceId spaceId, ulong saveDataId);
    Result GetSaveDataCommitId(out long commitId, SaveDataSpaceId spaceId, ulong saveDataId);
    Result UnregisterExternalKey(in RightsId rightsId);
    Result SetSdCardEncryptionSeed(in EncryptionSeed seed);
    Result SetSdCardAccessibility(bool isAccessible);
    Result IsSdCardAccessible(out bool isAccessible);
    Result OpenAccessFailureDetectionEventNotifier(ref SharedRef<IEventNotifier> outEventNotifier, ulong processId, bool notifyOnDeepRetry);
    Result GetAccessFailureDetectionEvent(out NativeHandle eventHandle);
    Result IsAccessFailureDetected(out bool isDetected, ulong processId);
    Result ResolveAccessFailure(ulong processId);
    Result AbandonAccessFailure(ulong processId);
    Result GetAndClearErrorInfo(out FileSystemProxyErrorInfo errorInfo);
    Result RegisterProgramIndexMapInfo(InBuffer programIndexMapInfoBuffer, int programCount);
    Result SetBisRootForHost(BisPartitionId partitionId, in FspPath path);
    Result SetSaveDataSize(long saveDataSize, long saveDataJournalSize);
    Result SetSaveDataRootPath(in FspPath path);
    Result DisableAutoSaveDataCreation();
    Result SetGlobalAccessLogMode(GlobalAccessLogMode mode);
    Result GetGlobalAccessLogMode(out GlobalAccessLogMode mode);
    Result OutputAccessLogToSdCard(InBuffer textBuffer);
    Result RegisterUpdatePartition();
    Result OpenRegisteredUpdatePartition(ref SharedRef<IFileSystemSf> outFileSystem);
    Result GetAndClearMemoryReportInfo(out MemoryReportInfo reportInfo);
    Result GetProgramIndexForAccessLog(out int programIndex, out int programCount);
    Result GetFsStackUsage(out uint stackUsage, FsStackUsageThreadType threadType);
    Result UnsetSaveDataRootPath();
    Result FlushAccessLogOnSdCard();
    Result OutputApplicationInfoAccessLog(in ApplicationInfo applicationInfo);
    Result OutputMultiProgramTagAccessLog();
    Result OverrideSaveDataTransferTokenSignVerificationKey(InBuffer key);
    Result CorruptSaveDataFileSystemByOffset(SaveDataSpaceId spaceId, ulong saveDataId, long offset);
    Result OpenMultiCommitManager(ref SharedRef<IMultiCommitManager> outCommitManager);
    Result OpenBisWiper(ref SharedRef<IWiper> outBisWiper, NativeHandle transferMemoryHandle, ulong transferMemorySize);
}
