from clarabot_nano.common.protocol.request import NanoBaseRequest


class AdminMkdirRequest(NanoBaseRequest):
    TYPE_KEY = "A-MKD"

    PATH = "path"
    NAME = "name"


class NanoFilesystemMoveRequest(NanoBaseRequest):
    TYPE_KEY = "FS-MOV"

    SRC_PATH = "src_path"  # source
    NEW_PATH = "new_path"  # target (must not exist)


class NanoFilesystemDeleteRequest(NanoBaseRequest):
    TYPE_KEY = "FS-DEL"

    PATH = "path"


class NanoFilesystemMkdirRequest(NanoBaseRequest):
    TYPE_KEY = "FS-MKD"

    PATH = "path"


class NanoFilesystemPutRequest(NanoBaseRequest):
    """
    Some of the fields have special meanings that trigger upload reset or finalization:
        - if OFFSET is 0 then the request starts or restarts an upload
        - if SIZE or MTIME for any part will mismatch the values from the (re)starting request, conflict error
          will be returned and the upload must be restarted
        - SMAC must be specified on the last part and it must be the hash of the hashes of all parts in order
        - the OFFSETs of all parts must build a range from 0 without gaps or overlaps
    """

    TYPE_KEY = "FS-PUT"

    # consistent path to upload the file to
    PATH = "path"  # final target path of the upload
    # metadata fields - may be omitted if not available, but must be consistent for all parts
    SIZE = "size"  # final size of the file in bytes
    MTIME = "mtime"  # unix timestamp when the file was last modified; in milliseconds
    # data chunking
    OFFSET = "offset"  # number of bytes to offset the writing of the data chunk
    DATA = "data"  # data chunk, optimally ~1MB
    # upload finalization
    SMAC = "smac"  # sum-hash of all parts in order
    # behaviour changes
    OVERWRITE = "overwrite"  # to allow overwriting the target path
