import { TokenCredential } from '@azure/identity';
import { z } from 'zod';
import { AzureKeyCredential } from '@azure/search-documents';

declare const indexResourceSchema: z.ZodObject<z.objectUtil.extendShape<{
    id: z.ZodString;
    name: z.ZodString;
    checksum: z.ZodString;
}, {
    type: z.ZodLiteral<"index">;
}>, "strip", z.ZodTypeAny, {
    id: string;
    checksum: string;
    type: "index";
    name: string;
}, {
    id: string;
    checksum: string;
    type: "index";
    name: string;
}>;
declare const indexerResourceSchema: z.ZodObject<z.objectUtil.extendShape<{
    id: z.ZodString;
    name: z.ZodString;
    checksum: z.ZodString;
}, {
    type: z.ZodLiteral<"indexer">;
}>, "strip", z.ZodTypeAny, {
    id: string;
    checksum: string;
    type: "indexer";
    name: string;
}, {
    id: string;
    checksum: string;
    type: "indexer";
    name: string;
}>;
declare const dataSourceResourceSchema: z.ZodObject<z.objectUtil.extendShape<{
    id: z.ZodString;
    name: z.ZodString;
    checksum: z.ZodString;
}, {
    type: z.ZodLiteral<"dataSource">;
}>, "strip", z.ZodTypeAny, {
    id: string;
    checksum: string;
    type: "dataSource";
    name: string;
}, {
    id: string;
    checksum: string;
    type: "dataSource";
    name: string;
}>;

/**
 * Type of the state that stores the status of migrations.
 */
type Migration = {
    /**
     * Randomly generated ID for the migration.  Ideally a v4 UUID.
     */
    id: string;
    /**
     * The complete name of the migration directory.
     *
     * @example `20241002131556-imperial-dragonfly.json`
     */
    migrationName: string;
    /**
     * The sha256 checksum of the migration file at the time the migration is applied.  Should never be overwritten.
     */
    checksum: string;
    /**
     * The timestamp at which the migration is started.  Written prior to any migration actions.
     */
    startedAt: Date;
    /**
     * The timestamp at which the migration successfully completed.  A non-null value indicates the migration succeeded.
     */
    finishedAt?: Date | null;
    /**
     * Any error messages that occurred during teh migration
     */
    logs?: string | null;
};
type ResourceType = "index" | "indexer" | "dataSource";
type IndexResource = z.infer<typeof indexResourceSchema>;
type IndexerResource = z.infer<typeof indexerResourceSchema>;
type DataSourceResource = z.infer<typeof dataSourceResourceSchema>;
type Resource = IndexResource | IndexerResource | DataSourceResource;
type StartMigrationArgs = Pick<Migration, "migrationName" | "checksum">;
interface Adapter {
    /**
     * If defined, runs before commands that interact with backend state.
     * Can be used to ensure backend provider is ready.
     */
    initialize?(): Promise<void>;
    listResources(): Promise<Resource[]>;
    updateResource(id: string, data: Partial<Resource>): Promise<void>;
    createResource(data: Omit<Resource, "id">): Promise<Resource>;
    deleteResource(name: string, type: ResourceType): Promise<void>;
    listMigrations(): Promise<Migration[]>;
    startMigration(migration: StartMigrationArgs): Promise<Migration>;
    succeedMigration(id: string): Promise<Migration>;
    errorMigration(id: string, error: string): Promise<Migration>;
}

type Config = {
    schema?: string;
    endpoint: string;
    credential: TokenCredential | AzureKeyCredential;
    adapter?: Adapter;
    /**
     * migrations output directory path, relative to the schema directory
     */
    out?: string;
};

/**
 * Determines whether a resource is a valid Resource.
 *
 * @param resource - The resource to evaluate.
 * @returns A boolean indicating whether the provided type is a Resource.
 */
declare function isResource(resource: any): resource is Resource;

export { type Adapter, type Config, type Migration, type Resource, type ResourceType, type StartMigrationArgs, isResource };
