
"""
 It is a extension to ReadFileOptions_Input with few more options.
"""
input ReadTextFileOptions_Input {
    etag: String
    Position: Int
    length: Int
    limits: ReadFileOptions_Input_limits

    """
     The optional acceptTextOnly parameters allows to fail this request early if the file
     contents are not textual.
    """
    acceptTextOnly: Boolean
    """
     The optional encoding parameter allows to specify the desired encoding when resolving
     the contents of the file.
    """
    encoding: String
    """
     The ioptional guessEncoding parameter allows to guess encoding from content of the file.
    """
    autoGuessEncoding: Boolean
}

"""
 It is an extension to WriteFileOptions_Input with few more options.
"""
input WriteTextFileOptions_Input {
    mtime: BigInt
    etag: String

    """
     The encoding to use when updating a file.
    """
    encoding: String
    """
     If set to true, will enforce the selected encoding and not perform any detection using BOM's.
    """
    overwriteEncoding: Boolean
    """
     Whether to overwrite a file even if is readonly.
    """
    overwriteReadonly: Boolean
    """
     Whether to write to the file as elevated (admin) user. When setting this option a prompt will
     ask the user to authenticate as super user.
    """
    writeElevated: Boolean
}

enum TextFileOperationResult {
	FILE_IS_BINARY
}

type ResourceEncoding {
    encoding: String
    hasBOM: Boolean
}

"""
 same as ModelState as in vscode
"""
enum FileModelState {
    """ A model is saved. """
    SAVED
    """ A model is dirty. """
    DIRTY
    """ A model is transitioning from dirty to saved. """
    PENDING_SAVE
    """
     A model is in conflict mode when changes cannot be saved because the
     underlying file has changed. Models in conflict mode are always dirty.
    """
    CONFLICT
    """ A model is in orphan state when the underlying file has been deleted. """
    ORPHAN
    """
     Any error that happens during a save that is not causing the CONFLICT state.
     Models in error mode are always dirty. """
    ERROR
    """ Loading """
    PENDING_LOAD
    """ Unkown """
    UNKNOWN
}

enum FileStateChange {
    DIRTY
    SAVING
    SAVE_ERROR
    SAVED
    REVERTED
    ENCODING
    CONTENT_CHANGE
    ORPHANED_CHANGE
}

enum FileContentStatus {
    PENDING
    START
    IN_PROGRESS
    END
    ERROR
    RESTORE
}

type FileResult {
    source: URI
    target: URI
    success: Boolean
}

enum SaveReason {
    EXPLICIT
    AUTO
    FOCUS_CHANGE
    WINDOW_CHANGE
}

enum FileLoadReason {
    EDITOR
    REFERENCE
    OTHER
}

"""
 # extension of IBaseStatWithMetadata
"""
interface IBaseTextFileContent {
    """
     The encoding of the content if known.
    """
    encoding: String
}

type TextFileContent implements IBaseTextFileContent & IBaseStatWithMetadata & IBaseStat {
    resource: URI!
    name: String!
    size: Int!
    mtime: BigInt!
    etag: String!
    isReadonly: Boolean
    encoding: String

    """
     The content of a text file.
    """   
    value: String
}

type TextFilePublishContent implements IBaseTextFileContent & IBaseStat {
    resource: URI!
    name: String!
    mtime: BigInt
    etag: String
    size: Int
    isReadonly: Boolean
    streamSeq: Int
    encoding: String
    """
     The content of the file in parts
    """
    value: String
    status: FileContentStatus
}

type TextFileStreamContent implements IBaseTextFileContent & IBaseStatWithMetadata  & IBaseStat {
    resource: URI!
    name: String!
    size: Int!
    mtime: BigInt!
    etag: String!
    isReadonly: Boolean
    encoding: String
    """
     The line grouped content of a text file.
    """
    value: TextBufferData
}

type TextBufferData {
    EOL: String
    lines: [String]
    containsRTL: Boolean
    isBasicASCII: Boolean
}

type UpdateDelayedResource {
    resource: URI
}

type UpdatedResource {
    resource: URI
    etag: String
}

input ModelLoadOrCreateOptions_Input_reload {
    async: Boolean
}

input ModelLoadOrCreateOptions_Input {
    """ Context why the model is being loaded or created."""
    reason: FileLoadReason
    """ The language mode to use for the model text content."""
    mode: String
    """ The encoding to use when resolving the model text content."""
    encoding: String
    """
     If the model was already loaded before, allows to trigger
     a reload of it to fetch the latest contents:
     - async: loadOrCreate() will return immediately and trigger
     a reload that will run in the background.
     - sync: loadOrCreate() will only return resolved when the
     model was finished reloading.
    """
    reload: ModelLoadOrCreateOptions_Input_reload
    """ Allow to load a model even if we think it is a binary file."""
    allowBinary: Boolean
}

input SaveOptions_Input {
    force: Boolean
    reason: SaveReason
    overwriteReadonly: Boolean
    overwriteEncoding: Boolean
    skipSaveParticipants: Boolean
    writeElevated: Boolean
}

input LoadOptions_Input {
    """ Go to disk bypassing any cahce of the model if any."""
    forceReadFromDisk: Boolean
    """ Allow to load a model even if we think it is a binary file."""
    allowBinary: Boolean
    """ Context why the model is being loaded."""
    reason: FileLoadReason
}

extend type Query {
    """
     Read the contents of a file identified by the resource.
    """
    readTextFile(resource: URI!, options: ReadTextFileOptions_Input): TextFileContent
    """
     Read the contents of a file identified by the resource as stream.
    """
    readStreamTextFile(resource: URI!, options: ReadTextFileOptions_Input): TextFileStreamContent
    readStringStreamTextFile(resource: URI!, options: ReadTextFileOptions_Input): TextFilePublishContent

}
# Mutations
extend type Mutation {
    """
     Read the contents of a file identified by the resource.

     Added inaddition to the query as we want to manipulate the cache with `update` option available in `mutation`.
     However, with apollo-client v3.0 we can start using it as `Query` as they support custom `merge`.
    """
    readTextFile(resource: URI!, options: ReadTextFileOptions_Input): TextFileContent
    """
     Create a file. If the file exists it will be overwritten with the contents if
     the options enable to overwrite.
    """
    createTextFile(resource: URI!, content: String, overwrite: Boolean): FileStatWithMetadata
    """
     Update a file with given contents.
    """
    writeTextFile(resource: URI!, value: String!, options: WriteTextFileOptions_Input!): FileStatWithMetadata
    """
     Delete a file. If the file is dirty, it will get reverted and then deleted from disk.
    """
    deleteTextFile(resource: URI!, useTrash: Boolean): Boolean
    """
     Move a file. If the file is dirty, its contents will be preserved and restored.
    """
    moveTextFile(source: URI!, target: URI!, overwrite: Boolean): FileStatWithMetadata

    writeChunk(resource: URI!, changes: [ChangesChunk_Input]!, options: WriteTextFileOptions_Input!): UpdatedResource
    writeChunkWithDelay(resource: URI!, changes: [ChangesChunk_Input]!, options: WriteTextFileOptions_Input!): UpdateDelayedResource
}

extend type Subscription {
    """
     Doesn't work yet
    """
    readStreamTextFile(resource: URI!): TextFileStreamContent
    """
     Streams content in string chunks
    """
    readStreamTextString(resource: URI!): TextFilePublishContent
}
