import { DecisionAnyMatch, InjectionResult } from "../constants.js";
import { Label } from "../logger.js";
import { Metafile } from "../parseTorrent.js";
import { Result } from "../Result.js";
import { Searchee, SearcheeWithInfoHash } from "../searchee.js";
import { ClientSearcheeResult, TorrentClient, TorrentMetadataInClient } from "./TorrentClient.js";
export default class Deluge implements TorrentClient {
    readonly url: string;
    readonly clientHost: string;
    readonly clientPriority: number;
    readonly clientType = Label.DELUGE;
    readonly readonly: boolean;
    readonly label: string;
    private delugeCookie;
    private delugeLabel;
    private delugeLabelSuffix;
    private isLabelEnabled;
    private delugeRequestId;
    constructor(url: string, clientHost: string, priority: number, readonly: boolean);
    /**
     * validates the login and host for deluge webui
     */
    validateConfig(): Promise<void>;
    /**
     * connects and authenticates to the webui
     */
    private authenticate;
    /**
     * ensures authentication and sends JSON-RPC calls to deluge
     * @param method RPC method to send (usually prefaced with module name)
     * @param params parameters for the method (usually in an array)
     * @param retries specify a retry count (optional)
     * @return a promised Result of the specified ResultType or an ErrorType
     */
    private call;
    /**
     * parses the set-cookie header and updates stored value
     * @param headers the headers from a request
     */
    private handleResponseHeaders;
    /**
     * checks enabled plugins for "Label"
     * @return boolean declaring whether the "Label" plugin is enabled
     */
    private labelEnabled;
    /**
     * checks the status of an infohash in the client and resumes if/when criteria is met
     * @param meta MetaFile containing torrent being resumed
     * @param decision decision by which the newTorrent was matched
     * @param options options object for extra flags
     * @param options.checkOnce boolean to only check for resuming once
     * @param options.meta metafile object containing the torrent data
     */
    resumeInjection(meta: Metafile, decision: DecisionAnyMatch, options: {
        checkOnce: boolean;
    }): Promise<void>;
    /**
     * generates the label for injection based on searchee and torrentInfo
     * @param searchee Searchee that contains the originating torrent
     * @param torrentInfo TorrentInfo from the searchee
     * @return string with the label for the newTorrent
     */
    private calculateLabel;
    /**
     * if Label plugin is loaded, adds (if necessary)
     * and sets the label based on torrent hash.
     * @param newTorrent the searchee of the newTorrent
     * @param label the destination label for the newTorrent/searchee
     */
    private setLabel;
    /**
     * injects a torrent into deluge client
     * @param newTorrent injected candidate torrent
     * @param searchee originating torrent (searchee)
     * @param decision decision by which the newTorrent was matched
     * @param options.onlyCompleted boolean to only inject completed torrents
     * @param options.destinationDir location of the linked files (optional)
     * @return InjectionResult of the newTorrent's injection
     */
    inject(newTorrent: Metafile, searchee: Searchee, decision: DecisionAnyMatch, options: {
        onlyCompleted: boolean;
        destinationDir?: string;
    }): Promise<InjectionResult>;
    recheckTorrent(infoHash: string): Promise<void>;
    /**
     * formats the json for rpc calls to inject
     * @param filename filename for the injecting torrent file
     * @param filedump string with encoded torrent file
     * @param destinationDir path to the torrent data
     * @param toRecheck boolean to recheck the torrent
     */
    private formatData;
    /**
     * returns directory of an infohash in deluge as a string
     * @param meta SearcheeWithInfoHash or Metafile for torrent to lookup in client
     * @param options options object for extra flags
     * @param options.onlyCompleted boolean to only return a completed torrent
     * @return Result containing either a string with path or reason it was not provided
     */
    getDownloadDir(meta: SearcheeWithInfoHash | Metafile, options: {
        onlyCompleted: boolean;
    }): Promise<Result<string, "NOT_FOUND" | "TORRENT_NOT_COMPLETE" | "UNKNOWN_ERROR">>;
    /**
     * returns map of hashes and download directories for all torrents
     * @param options.metas array of SearcheeWithInfoHash or Metafile for torrents to lookup in client
     * @param options.onlyCompleted boolean to only return completed torrents
     * @return Promise of a Map with hashes and download directories
     */
    getAllDownloadDirs(options: {
        onlyCompleted: boolean;
    }): Promise<Map<string, string>>;
    /**
     * checks if a torrent exists in deluge
     * @param inputHash the infoHash of the torrent to check
     * @return Result containing either a boolean or reason it was not provided
     */
    isTorrentInClient(inputHash: string): Promise<Result<boolean, Error>>;
    /**
     * checks if a torrent is complete in deluge
     * @param infoHash the infoHash of the torrent to check
     * @return Result containing either a boolean or reason it was not provided
     */
    isTorrentComplete(infoHash: string): Promise<Result<boolean, "NOT_FOUND">>;
    /**
     * checks if a torrent is checking in deluge
     * @param infoHash the infoHash of the torrent to check
     * @return Result containing either a boolean or reason it was not provided
     */
    isTorrentChecking(infoHash: string): Promise<Result<boolean, "NOT_FOUND">>;
    /**
     * @return All torrents in the client
     */
    getAllTorrents(): Promise<TorrentMetadataInClient[]>;
    /**
     * Get all searchees from the client and update the db
     * @param options.newSearcheesOnly only return searchees that are not in the db
     * @param options.refresh undefined uses the cache, [] refreshes all searchees, or a list of infoHashes to refresh
     * @return an object containing all searchees and new searchees (refreshed searchees are considered new)
     */
    getClientSearchees(options?: {
        newSearcheesOnly?: boolean;
        refresh?: string[];
    }): Promise<ClientSearcheeResult>;
    /**
     * returns information needed to complete/validate injection
     * @return Promise of TorrentInfo type
     * @param infoHash infohash to query for in the client
     * @param options options object for extra flags
     * @param options.useVerbose use verbose instead of error logging
     * @return Promise of TorrentInfo type
     */
    private getTorrentInfo;
}
