import { Actionable } from "../action/actionable";
import { SerializableData, StringKeyOf } from "../../../util/data";
import { Chained, Proxied } from "../action/chain";
import { ServiceAction } from "../action/serviceAction";
import { ScriptCtx } from "../elements/script";
type ServiceContentType = {
    [K in string]: any[];
};
export type ServiceHandlerCtx = ScriptCtx & {
    onAbort: (handler: () => void) => void;
};
export type ServiceHandler<Args extends any[]> = (ctx: ServiceHandlerCtx, ...args: Args) => void | Promise<void>;
export declare class ServiceSkeleton<Content extends ServiceContentType = ServiceContentType, RawData extends Record<string, SerializableData> | null = never> extends Actionable<RawData, ServiceSkeleton> {
    /**
     * Register an action handler
     * @param key action type
     * @param handler handler, the arguments are the same as the action content type
     */
    on<K extends StringKeyOf<Content>>(key: K, handler: ServiceHandler<Content[K]>): this;
    trigger<K extends StringKeyOf<Content>>(type: K, ...args: Content[K]): Proxied<this, Chained<ServiceAction, this>>;
}
declare class ServiceSkeletonMask<Content extends ServiceContentType = ServiceContentType, RawData extends Record<string, SerializableData> | null = never> extends ServiceSkeleton<Content, RawData> {
    private triggerAction;
    private toData;
    private fromChained;
    private chain;
    private proxy;
    private combineActions;
    private push;
    private getActions;
    private getSelf;
    private newChain;
    private id;
    private setId;
    private getId;
    private reset;
    private fromData;
    private construct;
    private __self;
    private __actions;
}
export declare abstract class Service<Content extends ServiceContentType = ServiceContentType, RawData extends Record<string, SerializableData> | null = Record<string, any>> extends ServiceSkeletonMask<Content, RawData> {
    /**
     * Serialize the service to data
     *
     * **Note**: data must be JSON serializable, return null if nothing needs to be saved
     */
    abstract serialize?(): RawData | null;
    /**
     * Load data to the service
     * @param data data exported from toData
     */
    abstract deserialize?(data: RawData): void;
    /**
     * Called when the service is initialized
     */
    abstract init?(): void;
}
export {};
