import { EntityProvider, EntityProviderConnection } from '@backstage/plugin-catalog-node';
import { Config } from '@backstage/config';
import { ResourceEntity } from '@backstage/catalog-model';
import { JsonValue } from '@backstage/types';
import { SchedulerServiceTaskScheduleDefinition, LoggerService, SchedulerServiceTaskRunner, SchedulerService } from '@backstage/backend-plugin-api';

/**
 * Annotation for specifying the certificate name of a node in PuppetDB.
 *
 * @public
 */
declare const ANNOTATION_PUPPET_CERTNAME = "puppet.com/certname";

/**
 * Configuration of {@link PuppetDbEntityProvider}.
 *
 * @public
 */
type PuppetDbEntityProviderConfig = {
    /**
     * ID of the provider.
     */
    id: string;
    /**
     * (Required) The base URL of PuppetDB API instance.
     */
    baseUrl: string;
    /**
     * (Optional) PQL query to filter PuppetDB nodes.
     */
    query?: string;
    /**
     * (Optional) Task schedule definition for the refresh.
     */
    schedule?: SchedulerServiceTaskScheduleDefinition;
};

/**
 * Customize the ingested Resource entity.
 *
 * @param node - The found PuppetDB node entry in its source format. This is the entry that you want to transform.
 * @param config - The configuration for the entity provider.
 *
 * @returns A `ResourceEntity` or `undefined` if you want to ignore the found group for being ingested by the catalog.
 *
 * @public
 */
type ResourceTransformer = (node: PuppetNode, config: PuppetDbEntityProviderConfig) => Promise<ResourceEntity | undefined>;
/**
 * A node in PuppetDB.
 *
 * @public
 */
type PuppetNode = {
    /**
     * The most recent time of fact submission from the associated certname.
     */
    timestamp: string;
    /**
     * The certname associated with the factset.
     */
    certname: string;
    /**
     * A hash of the factset's certname, environment, timestamp, facts, and producer_timestamp.
     */
    latest_report_status: string;
    /**
     *  The status of the latest report. Possible values come from Puppet's report status failed, changed, or unchanged.
     */
    hash: string;
    /**
     *  The most recent time of fact submission for the relevant certname from the Puppet Server.
     */
    producer_timestamp: string;
    /**
     * The certname of the Puppet Server that sent the factset to PuppetDB.
     */
    producer: string;
    /**
     * The environment associated with the fact.
     */
    environment: string;
    /**
     * The facts associated with the factset.
     */
    facts: PuppetFactSet;
};
/**
 * The set of all facts for a single certname in PuppetDB.
 *
 * @public
 */
type PuppetFactSet = {
    /**
     * The array of facts.
     */
    data: PuppetFact[];
    /**
     * The URL to retrieve more information about the facts.
     */
    href: string;
};
/**
 * A fact in PuppetDB.
 *
 * @public
 */
type PuppetFact = {
    /**
     * The name of the fact.
     */
    name: string;
    /**
     * The value of the fact.
     */
    value: JsonValue;
};

/**
 * A default implementation of the {@link ResourceTransformer}.
 *
 * @param node - The found PuppetDB node entry in its source format. This is the entry that you want to transform.
 * @param _config - The configuration for the entity provider.
 *
 * @returns A `ResourceEntity`.
 *
 * @public
 */
declare const defaultResourceTransformer: ResourceTransformer;

/**
 * Reads nodes from [PuppetDB](https://www.puppet.com/docs/puppet/6/puppetdb_overview.html)
 * based on the provided query and registers them as Resource entities in the catalog.
 *
 * @public
 */
declare class PuppetDbEntityProvider implements EntityProvider {
    private readonly config;
    private readonly logger;
    private readonly scheduleFn;
    private readonly transformer;
    private connection?;
    /**
     * Creates instances of {@link PuppetDbEntityProvider} from a configuration.
     *
     * @param config - The configuration to read provider information from.
     * @param deps - The dependencies for  {@link PuppetDbEntityProvider}.
     *
     * @returns A list of {@link PuppetDbEntityProvider} instances.
     */
    static fromConfig(config: Config, deps: {
        logger: LoggerService;
        schedule?: SchedulerServiceTaskRunner;
        scheduler?: SchedulerService;
        transformer?: ResourceTransformer;
    }): PuppetDbEntityProvider[];
    /**
     * Creates an instance of {@link PuppetDbEntityProvider}.
     *
     * @param config - Configuration of the provider.
     * @param logger - The instance of a {@link @backstage/backend-plugin-api#LoggerService}.
     * @param taskRunner - The instance of {@link @backstage/backend-plugin-api#SchedulerServiceTaskRunner}.
     * @param transformer - A {@link ResourceTransformer} function.
     *
     */
    private constructor();
    /** {@inheritdoc @backstage/plugin-catalog-node#EntityProvider.connect} */
    connect(connection: EntityProviderConnection): Promise<void>;
    /** {@inheritdoc @backstage/plugin-catalog-node#EntityProvider.getProviderName} */
    getProviderName(): string;
    /**
     * Creates a function that can be used to schedule a refresh of the catalog.
     *
     * @param taskRunner - The instance of {@link @backstage/backend-plugin-api#SchedulerServiceTaskRunner}.
     */
    private createScheduleFn;
    /**
     * Refreshes the catalog by reading nodes from PuppetDB and registering them as Resource Entities.
     *
     * @param logger - The instance of a Logger.
     */
    refresh(logger: LoggerService): Promise<void>;
}

/**
 * Name of the default provider when a using a simple configuration.
 *
 * @public
 */
declare const DEFAULT_PROVIDER_ID = "default";

export { ANNOTATION_PUPPET_CERTNAME, DEFAULT_PROVIDER_ID, PuppetDbEntityProvider, type PuppetDbEntityProviderConfig, type PuppetFact, type PuppetFactSet, type PuppetNode, type ResourceTransformer, defaultResourceTransformer };
