import { Dispatcher } from './dispatcher.ts';
import { Package } from './package.ts';
import { Packages } from './packages.ts';
import { IFetch } from './types.ts';
export type PackageLike = Package | string;
export interface IPackageReceipt {
    /**
     * Package name.
     */
    name: string;
    /**
     * File name.
     */
    file: string;
    /**
     * File size.
     */
    size: number;
    /**
     * SHA256 hash of the file contents.
     */
    sha256: string;
    /**
     * Source, URL for root or file path for children.
     */
    source: string;
}
export interface IPackageInstallBefore {
    /**
     * Package instance.
     */
    package: Package;
}
export interface IPackageInstallAfter {
    /**
     * Package instance.
     */
    package: Package;
}
export interface IPackageInstallCurrent {
    /**
     * Package instance.
     */
    package: Package;
}
export interface IPackageDownloadBefore {
    /**
     * Package instance.
     */
    package: Package;
}
export interface IPackageDownloadAfter {
    /**
     * Package instance.
     */
    package: Package;
}
export interface IPackageDownloadProgress {
    /**
     * Package instance.
     */
    package: Package;
    /**
     * Progress total.
     */
    total: number;
    /**
     * Progress amount.
     */
    amount: number;
}
export interface IPackageCleanupBefore {
    /**
     * Package name.
     */
    package: string;
}
export interface IPackageCleanupAfter {
    /**
     * Package name.
     */
    package: string;
    /**
     * Package removed.
     */
    removed: boolean;
}
export interface IPackageInstalled {
    /**
     * Package installed.
     */
    package: Package;
    /**
     * List of packages used in install, empty if already installed.
     */
    install: Package[];
}
export interface IPackageRemovedObsolete {
    /**
     * Package removed.
     */
    package: string;
    /**
     * Removed or already removed.
     */
    removed: boolean;
}
/**
 * Package manager.
 */
export declare class Manager {
    /**
     * Root path.
     */
    readonly path: string;
    /**
     * The default headers for HTTP requests.
     */
    headers: {
        [header: string]: string;
    };
    /**
     * A fetch-like interface requiring only a sebset of features.
     */
    fetch: IFetch | null;
    /**
     * Package install before events.
     */
    readonly eventPackageInstallBefore: Dispatcher<IPackageInstallBefore>;
    /**
     * Package install after events.
     */
    readonly eventPackageInstallAfter: Dispatcher<IPackageInstallAfter>;
    /**
     * Package install current events.
     */
    readonly eventPackageInstallCurrent: Dispatcher<IPackageInstallCurrent>;
    /**
     * Package download before events.
     */
    readonly eventPackageDownloadBefore: Dispatcher<IPackageDownloadBefore>;
    /**
     * Package download after events.
     */
    readonly eventPackageDownloadAfter: Dispatcher<IPackageDownloadAfter>;
    /**
     * Package download progress events.
     */
    readonly eventPackageDownloadProgress: Dispatcher<IPackageDownloadProgress>;
    /**
     * Package cleanup before events.
     */
    readonly eventPackageCleanupBefore: Dispatcher<IPackageCleanupBefore>;
    /**
     * Package cleanup after events.
     */
    readonly eventPackageCleanupAfter: Dispatcher<IPackageCleanupAfter>;
    /**
     * Packages instance.
     */
    protected readonly _packages: Packages;
    /**
     * Manager constructor.
     *
     * @param path The path, defaults to environment variable or relative.
     */
    constructor(path?: string | null);
    /**
     * Packages URL.
     *
     * @returns The URL.
     */
    get packagesUrl(): string;
    /**
     * Packages file.
     *
     * @returns The file.
     */
    get packagesFile(): string;
    /**
     * Package file.
     *
     * @returns The path.
     */
    get packageFile(): string;
    /**
     * Meta directory.
     *
     * @returns The directory.
     */
    get metaDir(): string;
    /**
     * Packages loaded.
     *
     * @returns Is loaded.
     */
    get loaded(): boolean;
    /**
     * Assert instance all loaded, including the packages list.
     * Implies all active assertions.
     */
    assertLoaded(): void;
    /**
     * Ensure load if exists.
     */
    ensureLoad(): Promise<void>;
    /**
     * Ensure loaded.
     */
    ensureLoaded(): Promise<void>;
    /**
     * Load packages if exist.
     */
    load(): Promise<void>;
    /**
     * Iterate over the packages.
     *
     * @yields Package object.
     */
    packages(): AsyncGenerator<Package, void, unknown>;
    /**
     * Get package by the unique name.
     *
     * @param name Package name.
     * @returns The package or null.
     */
    packageByName(name: string): Promise<Package | null>;
    /**
     * Get package by the sha256 hash.
     *
     * @param sha256 Package sha256.
     * @returns The package or null.
     */
    packageBySha256(sha256: string): Promise<Package | null>;
    /**
     * Get package by the sha1 hash.
     *
     * @param sha1 Package sha1.
     * @returns The package or null.
     */
    packageBySha1(sha1: string): Promise<Package | null>;
    /**
     * Get package by the md5 hash.
     *
     * @param md5 Package md5.
     * @returns The package or null.
     */
    packageByMd5(md5: string): Promise<Package | null>;
    /**
     * Get package by the unique value.
     *
     * @param unique Package unique.
     * @returns The package or null.
     */
    packageByUnique(unique: string): Promise<Package | null>;
    /**
     * Read package install receipt.
     *
     * @param pkg The package.
     * @returns Install receipt.
     */
    receipt(pkg: PackageLike): Promise<IPackageReceipt>;
    /**
     * Get package install file.
     *
     * @param pkg The package.
     * @returns Path to install file.
     */
    file(pkg: PackageLike): Promise<string>;
    /**
     * Verify package install file, using size and hash.
     *
     * @param pkg The package.
     */
    packageInstallVerify(pkg: PackageLike): Promise<void>;
    /**
     * Update the package manager installed data.
     * Updates the packages list.
     *
     * @returns Update report.
     */
    update(): Promise<{
        updated: import("./packages.ts").IPackageUpdated[];
        added: import("./packages.ts").IPackageUpdated[];
        removed: import("./packages.ts").IPackageUpdated[];
    }>;
    /**
     * Check if a package is installed.
     *
     * @param pkg The package.
     * @returns True if already installed, else false.
     */
    isInstalled(pkg: PackageLike): Promise<boolean>;
    /**
     * Check if a package is installed and up-to-date.
     *
     * @param pkg The package.
     * @returns True if already up-to-date, else false.
     */
    isCurrent(pkg: PackageLike): Promise<boolean>;
    /**
     * List all installed packages.
     *
     * @returns A list of installed package objects.
     */
    installed(): Promise<Package[]>;
    /**
     * List all outdated packages.
     *
     * @returns The list of outdated package objects.
     */
    outdated(): Promise<Package[]>;
    /**
     * Upgrade any outdated packages.
     *
     * @returns List of packages upgraded.
     */
    upgrade(): Promise<IPackageInstalled[]>;
    /**
     * Install package.
     * Returns the list of packages processed to install.
     * Returns empty array if current version is already installed.
     *
     * @param pkg The package.
     * @returns List of packages processed to complete the install.
     */
    install(pkg: PackageLike): Promise<Package[]>;
    /**
     * Remove package.
     *
     * @param pkg The package.
     * @returns True if removed, false if nothing to remove.
     */
    remove(pkg: PackageLike): Promise<boolean>;
    /**
     * Check if package name is obsolete.
     *
     * @param pkg The package.
     * @returns True if package obslete, else false.
     */
    isObsolete(pkg: string): Promise<boolean>;
    /**
     * List obsolete package names.
     *
     * @returns A list of obsolete package names.
     */
    obsolete(): Promise<string[]>;
    /**
     * Cleanup all obsolete and outdated packages.
     *
     * @returns Lists of removed packages.
     */
    cleanup(): Promise<IPackageRemovedObsolete[]>;
    /**
     * Join path on the base path.
     *
     * @param parts Path parts.
     * @returns Joined path.
     */
    pathTo(...parts: string[]): string;
    /**
     * Join path on the meta path.
     *
     * @param parts Path parts.
     * @returns Joined path.
     */
    pathToMeta(...parts: string[]): string;
    /**
     * Join path on package base path.
     *
     * @param pkg The package.
     * @param parts Path parts.
     * @returns Joined path.
     */
    pathToPackage(pkg: PackageLike, ...parts: string[]): Promise<string>;
    /**
     * Join path on package meta path.
     *
     * @param pkg The package.
     * @param parts Path parts.
     * @returns Joined path.
     */
    pathToPackageMeta(pkg: PackageLike, ...parts: string[]): Promise<string>;
    /**
     * Get package object by object, name, or hash.
     * Throw error if package is unknown.
     *
     * @param pkg The package.
     * @returns Package object.
     */
    protected _asPackage(pkg: PackageLike): Promise<Package>;
    /**
     * Get package name by object, name, or hash.
     * If package object is passed, uses name from the object.
     * If string is passed and unknown, returns that same string.
     *
     * @param pkg The package.
     * @returns Package object.
     */
    protected _asName(pkg: PackageLike): Promise<string>;
    /**
     * Write package installed receipt.
     *
     * @param pkg The package.
     */
    protected _packageMetaReceiptWrite(pkg: PackageLike): Promise<void>;
    /**
     * Create package installed receipt object from a package.
     *
     * @param pkg The package.
     * @returns Receipt object.
     */
    protected _packageMetaReceiptFromPackage(pkg: PackageLike): Promise<IPackageReceipt>;
    /**
     * Ensure package directory exists.
     *
     * @param pkg The package.
     */
    protected _packageDirsEnsure(pkg: PackageLike): Promise<void>;
    /**
     * Ensure fetch-like function is set.
     *
     * @returns The fetch-like function.
     */
    protected _ensureFetch(): IFetch;
    /**
     * Get fetch error messsage.
     *
     * @param error Error object.
     * @returns Error message.
     */
    protected _fetchErrorMessage(error: Error): string;
    /**
     * List directories under package manger control.
     *
     * @returns The recognized package directories.
     */
    protected _packageDirectories(): Promise<string[]>;
    /**
     * Request the packages file.
     *
     * @returns File contents as string.
     */
    protected _requestPackages(): Promise<string>;
    /**
     * Ensure base directories exists.
     */
    protected _ensureDirs(): Promise<void>;
    /**
     * Create the main path.
     *
     * @param path The path, defaults to environment variable or relative.
     * @returns Main path.
     */
    protected _createPath(path: string | null): string;
    /**
     * Create the Packages instance.
     *
     * @returns Packages instance.
     */
    protected _createPackages(): Packages;
}
