import { AlChangeStamp } from '@al/core';

/**
 * Nothing is complete without at least two aliases
 */
export declare const AlConvergenceUtilityClient: ConvergenceUtilityClientInstance;

export declare interface AlWSMAppliance {
    appliance_id: number;
    appliance_name: string;
    customer_id: number;
    customer_name: string;
    zone_id: number;
    uuid: string;
    mte_appliance: number;
    create_date: number;
    features: string[];
}

export declare const AlWSMClient: AlWSMClientInstance;

export declare class AlWSMClientInstance {
    private readonly serviceStack;
    /**
     * Get all appliances using an specific accountId
     * GET
     * /api/appliance/select?features=wsm_enabled&customer_ids={accountId}
     * @param accountId AIMS Account ID
     * @returns a promise with an array of appliances of a specific accountId
     *
     * @remarks
     */
    getAppliances(accountId: string): Promise<AlWSMAppliance[]>;
    /**
     * Get an appliance's full data using an specific applianceUuid
     * GET
     * /api/wsm/config/appliance/{applianceUuid}
     *
     * @param accountId AIMS Account ID
     * @param applianceUuid Appliance UUID
     * @returns a promise with the an Appliance object with all its properties
     *
     * @remarks
     */
    getApplianceInfo(applianceUuid: string): Promise<AlWSMConfigAppliance>;
    /**
     * Get availability of the appliance UI
     * GET
     * /wsm/manage/appliance/${applianceUuid}/auth.html?mode=login
     *
     * @param applianceUuid Appliance UUID
     * @returns a promise with returning true if the UI is up, otherwise false
     *
     * @remarks
     */
    getWafUiAvailability(applianceUuid: string): Promise<unknown>;
    /**
     * Get Stats
     * GET
     * /wsm/stats/${type}/select
     *
     * @param type 'network'|'proxy'|'system'
     * @param accountId AIMS Account ID
     * @param applianceUuids Appliance UUID array of string
     * @param fields all allowed fields to get
     * @returns a promise with returning an array of StatsInfo object
     *
     * @remarks
     */
    getStats(type: StatType, accountId: string, applianceUuids: string[], fields: StatField[]): Promise<StatsInfo[]>;
}

export declare interface AlWSMConfigAppliance {
    proxy: {
        [key: string]: ProxyInfo;
    };
    system: SystemInfo;
}

export declare interface ApplianceAssignmentConfig {
    appliances?: string[];
    secondary_appliances?: string[];
}

export declare interface ApplianceZoneRecord {
    zone_id?: string;
    name?: string;
}

export declare interface CertificateKeyPair {
    id?: string;
    certificate?: string[];
    private_key?: string[];
    encrypted_private_key?: string;
    name?: string;
    type?: string;
    created?: AlChangeStamp;
    modified?: AlChangeStamp;
    _certificate?: string;
    _private_key?: string;
}

export declare interface CloudExplorerAwsRegionRecord {
    id: string;
    name: string;
}

export declare interface CollectionAlertConfig {
    alert_threshold?: number;
    emails?: string[];
    is_enabled?: boolean;
    send_once?: boolean;
    send_threshold?: number;
}

export declare interface CollectionCredential {
    created?: AlChangeStamp;
    modified?: AlChangeStamp;
    id?: string;
    name?: string;
    type?: string;
    password?: {
        password: string;
        username: string;
    };
    iam_role?: {
        arn: string;
        external_id: string;
    };
    azure_shared_key?: {
        account_key: string;
        account_name: string;
    };
    azure_ad_user?: {
        active_directory_id: string;
        username: string;
    };
}

export declare interface CollectionFilter {
    field?: string;
    name: string;
    product: string[];
    type: string;
    values: CollectionFilterValue[];
}

export declare type CollectionFiltersResponse = {
    filters: CollectionFilter[];
};

export declare type CollectionFilterValue = ICollectionFilterValue | string;

export declare interface CollectionHistory {
    key?: string;
    timestamp?: number;
    metadata?: CollectionHistoryMetadata;
    status?: CollectionHistoryStatus;
    details?: CollectionHistoryDetail[];
}

export declare interface CollectionHistoryDetail {
    status?: string;
    error?: string;
    warning?: string;
}

export declare interface CollectionHistoryMetadata {
    host_type?: string;
    local_hostname?: string;
    local_ipv4?: string[];
    local_ipv6?: string[];
    public_hostname?: string;
    public_ipv4?: string[];
    public_ipv6?: string[];
    num_logical_processors?: number;
    os_details?: string;
    os_type?: string;
    total_mem_mb?: number;
    version?: string;
    ec2_instance_id?: string;
    ec2_ami_id?: string;
    ec2_instance_type?: string;
    ec2_account_id?: string;
    ec2_region?: string;
    ec2_availability_zone?: string;
    sqs_endpoint?: string;
    sqs_queue_name?: string;
}

export declare interface CollectionHistoryStatus {
    details?: any[];
    status?: string;
    timestamp?: number;
    updated?: number;
    stream?: string;
    reported_by?: string;
    inst_type: string;
    host_id?: string;
}

export declare interface CollectionPolicy {
    id?: string;
    name?: string;
    type?: string;
    product_type?: string;
    collect_from_discovered?: boolean;
    default?: boolean;
    streams?: any[];
    created?: AlChangeStamp;
    modified?: AlChangeStamp;
    template_id?: string;
    alert_type?: string;
    target_type?: string;
    enabled?: boolean;
    when?: string;
    time_zone?: string;
    netmask?: string;
    restrict_network?: boolean;
    whitelist?: {
        rules?: WhiteListConfigRule[];
        policy?: {
            id?: string;
            name?: string;
        };
    };
    monitoring?: MonitoringConfig;
    s3?: S3Config;
    tmhost?: HostConfig;
    flatfile?: FlatFileConfig;
    appliance_assignment?: ApplianceAssignmentConfig;
    collection_alert?: CollectionAlertConfig;
    schedule?: UpdatesScheduleConfig[];
    credential?: any;
}

export declare interface CollectionSchedule {
    blackout?: CollectionScheduleBlackout;
    name?: string;
    id?: string;
    timezone?: string;
    created?: AlChangeStamp;
    modified?: AlChangeStamp;
}

export declare interface CollectionScheduleBlackout {
    enabled?: boolean;
    periods?: CollectionScheduleBlackoutPeriod[];
}

export declare interface CollectionScheduleBlackoutPeriod {
    start_minute?: string;
    start_hour?: string;
    end_minute?: string;
    end_hour?: string;
}

export declare interface CollectionsGenericResponse {
    credentials?: {
        credential: CollectionCredential;
    }[];
    policies?: {
        policy: CollectionPolicy;
    }[];
    schedules?: {
        schedule: CollectionSchedule;
    }[];
    sources?: {
        source: CollectionSource;
    }[];
    collectors?: {
        source: CollectionSource;
    }[];
    hosts?: {
        source: CollectionSource;
    }[];
    networks?: {
        source: CollectionSource;
    }[];
    keypairs?: {
        keypair: CertificateKeyPair;
    }[];
    history?: CollectionHistory[];
    total_count?: number;
}

export declare interface CollectionSource {
    source?: CollectionSourceValue;
    host?: CollectionSourceValue;
    is_archived?: boolean;
}

export declare interface CollectionSourceConfig {
    collection_method?: string;
    template_id?: string;
    collection_type?: string;
    network?: {
        address: string;
    };
    policy?: {
        id?: string;
        name?: string;
    };
    azure_events?: {
        credential?: any;
        filters?: any[];
        subscription_id?: string;
    };
    azure_table?: {
        table_name?: string;
        credential?: any;
    };
    azure_blob?: {
        app_service_name?: string;
        credential?: any;
        config_type?: string;
        container?: string;
    };
    time_zone?: string;
    max_collection_interval?: string;
    s3aws?: any;
    s3?: any;
    tmappliance?: any;
}

export declare interface CollectionSourceValue {
    network_id?: string;
    registered?: boolean;
    role?: boolean;
    collection_alerts?: string[];
    config?: CollectionSourceConfig;
    created?: AlChangeStamp;
    modified?: AlChangeStamp;
    customer?: {
        id: string;
    };
    enabled?: boolean;
    host?: {
        id: string;
        ip_address?: string;
    };
    appliance?: any;
    id?: string;
    name?: string;
    product_type?: string;
    stats?: {
        [k: string]: number | string;
    };
    status?: CollectionHistoryStatus;
    tags?: {
        name: string;
    }[];
    type?: string;
    metadata?: CollectionHistoryMetadata;
    assignmentPolicy?: {
        id: string;
    };
    update_policy?: any;
    deployment?: any;
    monitoring?: {
        policy?: {
            id?: string;
            name?: string;
        };
    };
    timestamp?: AlChangeStamp;
    whitelist?: any;
}

export declare interface CollectionUpdatesPolicyScheduleDaysConfig {
    how: string;
    weekly?: string[];
    monthly?: number[];
}

export declare interface CollectionUpdatesPolicyScheduleTimeConfig {
    from: TimeConfig;
    to: TimeConfig;
}

export declare type ConvergenceQueryParams = {
    [i: string]: string | number | boolean;
};

export declare class ConvergenceUtilityClientInstance {
    private readonly serviceName;
    private readonly serviceVersion;
    private readonly serviceStack;
    constructor();
    listApplianceZones(accountId: string): Promise<ZoneMembershipResponse>;
    getOneApplianceZone(// TODO: improve this response object
    accountId: string, applianceId: string): Promise<ApplianceZoneRecord>;
    listLogSources(accountId: string, deploymentId: 'all' | 'datacenter' | 'manual' | 'dc-logsources', params?: ConvergenceQueryParams, action?: 'massedit' | 'deleted' | null): Promise<CollectionsGenericResponse>;
    listProtectedHosts(accountId: string, deploymentId: string, params?: ConvergenceQueryParams, action?: 'massedit' | 'deleted' | null): Promise<CollectionsGenericResponse>;
    listNetworks(accountId: string, deploymentId: string, params?: ConvergenceQueryParams): Promise<CollectionsGenericResponse>;
    createNetwork(accountId: string, deploymentId: string, data: CollectionSource): Promise<CollectionSource>;
    getOneNetwork(accountId: string, deploymentId: string, networkId: string): Promise<CollectionSource>;
    listAppliances(accountId: string, deploymentId: string, params?: {
        [i: string]: number | string | boolean;
    }): Promise<CollectionsGenericResponse>;
    getOneAppliance(accountId: string, deploymentId: string, applianceId: string): Promise<CollectionSource>;
    updateAppliance(accountId: string, deploymentId: string, applianceId: string, data: CollectionSource): Promise<CollectionSource>;
    getHostHistory(accountId: string, hostId: string, type: 'metadata' | 'status'): Promise<CollectionsGenericResponse>;
    getAgentVersion(accountId: string, hostId: string): Promise<{
        agentVersion: string;
    }>;
    listHosts(accountId: string, deploymentId: string, productType: string, params?: ConvergenceQueryParams, action?: 'massedit' | 'deleted' | null): Promise<CollectionsGenericResponse>;
    listCredentials(accountId: string, params?: ConvergenceQueryParams): Promise<CollectionsGenericResponse>;
    getOneCredential(accountId: string, credentialId: string): Promise<CollectionCredential>;
    deleteOneCredential(accountId: string, credentialId: string): Promise<void>;
    listAlertRules(accountId: string, productType: string, params?: ConvergenceQueryParams): Promise<CollectionsGenericResponse>;
    getAlertRule(accountId: string, productType: string, ruleId: string): Promise<CollectionPolicy>;
    deleteAlertRule(accountId: string, productType: string, ruleId: string): Promise<void>;
    updateAlertRule(accountId: string, productType: string, ruleId: string, data: CollectionPolicy): Promise<CollectionPolicy>;
    createAlertRule(accountId: string, productType: string, data: CollectionPolicy): Promise<CollectionPolicy>;
    createPolicy(accountId: string, policyType: PolicyType, data: CollectionPolicy): Promise<CollectionPolicy>;
    getOnePolicy(accountId: string, policyType: PolicyType, policyId: string): Promise<CollectionPolicy>;
    isPolicyDeletable(accountId: string, policyType: PolicyType, policyId: string): Promise<boolean>;
    isCredentialDeletable(accountId: string, credentialId: string): Promise<boolean>;
    deletePolicy(accountId: string, policyType: PolicyType, policyId: string): Promise<void>;
    listPolicies(accountId: string, policyType: PolicyType, params?: ConvergenceQueryParams): Promise<CollectionsGenericResponse>;
    updatePolicy(accountId: string, policyType: PolicyType, policyId: string, data: CollectionPolicy): Promise<CollectionPolicy>;
    updateCollector(accountId: string, deploymentId: string, collectorId: string, data: any): Promise<CollectionSource>;
    getOneCollector(accountId: string, deploymentId: string, collectorId: string): Promise<CollectionSource>;
    listCollectors(accountId: string, deploymentId: string, params?: {
        [i: string]: number | string | boolean;
    }): Promise<CollectionsGenericResponse>;
    createCollection(accountId: string, deploymentId: string, data: any, entityType?: string): Promise<CollectionsGenericResponse>;
    updateCollection(accountId: string, deploymentId: string, collectionId: string, data: any, entityType?: string): Promise<CollectionsGenericResponse>;
    getCloudExplorerAwsRegions(accountId: string): Promise<CloudExplorerAwsRegionRecord[]>;
    deleteCollectionSource(accountId: string, deploymentId: string, collectionId: string, entityType?: string, action?: 'massedit' | 'deleted' | null): Promise<void>;
    getCollectionSource(accountId: string, deploymentId: string, collectionId: string): Promise<CollectionSource>;
    listCollectionSources(accountId: string, deploymentId: string, params?: ConvergenceQueryParams): Promise<CollectionsGenericResponse>;
    listCloudDefenderCollectionSources(accountId: string, params?: ConvergenceQueryParams): Promise<CollectionsGenericResponse>;
    addToCase(accountId: string, data: {
        id: string;
        type: string;
    }): Promise<any>;
    getFiltersByEntityType(accountId: string, entityType: string): Promise<CollectionFiltersResponse>;
    lookUpUsers(accountId: string, userIds: string[]): Promise<LookedUpUsersResponse>;
    getDownloads(accountId: string, product: string): Promise<any>;
    getApiKey(accountId: string): Promise<any>;
    listCertificateKeyPairs(accountId: string, params?: ConvergenceQueryParams): Promise<CollectionsGenericResponse>;
    createCertificateKeyPair(accountId: string, data: CertificateKeyPair): Promise<CertificateKeyPair>;
    deleteCertificateKeyPair(accountId: string, keypairId: string): Promise<void>;
    validatePemFile(accountId: string, file: File): Promise<string[][]>;
    exportRecords(accountId: string, deploymentId: string, type: ExportableRecordsType, params?: ConvergenceQueryParams): Promise<string>;
}

export declare type ExportableRecordsType = 'protectedhosts' | 'lmhosts' | 'tmhosts' | 'appliances' | 'networks' | 'collection_deleted' | 'collection';

export declare interface FlatFileConfig {
    filename_integer_pattern?: string;
    filename_timestamp_pattern?: string;
    multiline?: MultilineConfig;
    name?: string;
    path?: string;
    timestamp?: TimestampConfig;
}

export declare interface HostConfig {
    policyId?: string;
    name?: string;
    defaultState?: any;
    createdBy?: string;
    createdDate?: string;
    updatedBy?: string;
    updatedDate?: string;
    udp?: boolean;
    packet_size?: number;
    encrypt?: boolean;
    compress?: boolean;
}

export declare interface ICollectionFilterValue {
    name?: string;
    product?: string;
    value?: string;
}

export declare type LookedUpUsersResponse = {
    users: {
        [id: string]: UserData;
    };
};

export declare interface MonitoringConfig {
    networks: {
        id: string;
    }[];
    whitelists: {
        id: string;
    }[];
}

export declare interface MultilineConfig {
    continuation?: string;
    is_multiline?: boolean;
    is_regex?: boolean;
    line_count?: string;
    operator?: string;
    pattern?: string;
}

export declare type PolicyType = 'eventlogs' | 's3' | 'flatfile' | 'assignment' | 'monitoring' | 'host' | 'syslog' | 'updates' | 'whitelist';

export declare interface ProxyInfo {
    settings: {
        bind: unknown[];
        class: {
            [key: string]: {
                [key: string]: number | string;
            };
        };
        error: {
            auth: {
                deny: number;
            };
            param: {
                deny: number;
            };
            url: {
                deny: number;
            };
            r403: number;
            r404: number;
            r502: number;
            sc: number;
            sri: number;
        };
        id: number;
        name: string | null;
        sec: SecInfo;
        ver: number[];
        vhost: {
            as: unknown;
            name: string;
            port: string;
            proto: string;
            port2: unknown;
            proxy_protocol_enabled: number;
        };
        adv: unknown;
        attack_c_l: unknown;
        criticality_a_l: unknown;
        email_a_l: number;
        err_pages: {
            [key: string]: unknown[];
        };
        hc: unknown[];
        learn: unknown;
        loadbalance: unknown;
        migrations: number;
        rhost: unknown[];
        sbrl: number;
        syslog_a_l: number;
        v_act: unknown[];
        whitelist: unknown[];
    };
}

export declare interface S3Config {
    multiline?: MultilineConfig;
    timestamp?: TimestampConfig;
}

export declare interface SecInfo {
    header: {
        be: number;
        length: number;
        pragma: number;
        strict: number;
        br: [string[]];
        ve: number;
        vp: number;
    };
    key: string;
    mode: string;
    nt: number;
    td: {
        [key: string]: [] | number;
    };
    ts: number;
    us: {
        [key: string]: [unknown[]];
    };
    buri: {
        enabled: number;
        list: unknown[];
    };
    c_enc: number;
    c_enc_iter: number;
    cloak: number;
    cloak_e: number;
    cloak_ee: unknown[];
    cs: unknown[];
    csrf: {
        re: unknown[];
        re_e: number;
    };
    cv: number;
    dpnb: number;
    epe: number;
    fvb: number;
    gparam: {
        enabled: number;
        list: unknown[];
        v: number;
    };
    gparam_sc: {
        enabled: number;
    };
    guri: {
        enabled: number;
        list: unknown[];
        v: number;
    };
    guri_sc: {
        enabled: number;
    };
    ma: number;
    mab: number;
    mode_date: number;
    mpb: number;
    passthru: number;
    pct_u_enc: number;
    pf_pass: number;
    post_max_len: number;
    rae: number;
    regex: string;
    rv: number;
    sbi: number;
    sbi_l: number;
    scv: number;
    sp: unknown;
    static_ext_pc: string;
    static_ext_regex: string;
    static_pass: {
        enabled: number;
    };
    svb: number;
    tce: number;
    tpa: number;
    upload: {
        enabled: number;
        fname: {
            e: number;
            re: string;
        };
        ext_ban: {
            e: number;
            ce: number;
            cext: unknown[];
        };
        filesize: number;
        maxfiles: number;
        maxsize: number;
    };
    vpg: unknown[];
    vs: number;
}

export declare type StatField = "uuid" | "applianceName" | "interface" | "timeslice" | "interval" | "ipackets" | "opackets" | "ierrors" | "oerrors" | "ibytes" | "obytes" | "core_handled" | "core_requests" | "core_accepted" | "core_waiting" | "core_active" | "core_reading" | "core_writing" | "cpu_usage" | "mem_usage" | "proxy" | "websiteName" | "total" | "compressed" | "cached" | "bytes_orig" | "bytes_sent" | "bytes_recv" | "code_ok" | "code_redirect" | "code_denied" | "code_not_found" | "code_internal_error" | "code_gateway_error" | "code_other";

export declare interface StatsInfo {
    uuid?: string;
    applianceName?: string;
    interface?: string;
    timeslice?: string;
    interval?: string;
    ipackets?: string;
    opackets?: string;
    ierrors?: string;
    oerrors?: string;
    ibytes?: string;
    obytes?: string;
    core_handled?: string;
    core_requests?: string;
    core_accepted?: string;
    core_waiting?: string;
    core_active?: string;
    core_reading?: string;
    core_writing?: string;
    cpu_usage?: string;
    mem_usage?: string;
    proxy?: string;
    websiteName?: string;
    total?: string;
    compressed?: string;
    cached?: string;
    bytes_orig?: string;
    bytes_sent?: string;
    bytes_recv?: string;
    code_ok?: string;
    code_redirect?: string;
    code_denied?: string;
    code_not_found?: string;
    code_internal_error?: string;
    code_gateway_error?: string;
    code_other?: string;
}

export declare type StatType = 'network' | 'proxy' | 'system';

export declare interface SystemInfo {
    http: {
        global_emerging_threats: number;
    };
    interfaces: unknown;
    log: {
        s3: unknown[];
    };
    system: {
        dns: string[];
        hostname: string;
        info: {
            cpu_count: number;
            transparent_proxy_enabled: number;
        };
        proxy: unknown[];
        ssh: number;
        sync: {
            acl: unknown[];
            cluster_id: string;
        };
        ap: [];
        captcha: {
            token: {
                key: string;
                iv: string;
            };
        };
        cert_metadata: {
            mgui: [string[]];
        };
        contact: string;
        gateway: string;
        ntp: string[];
        smtp: string;
        timezone: string;
    };
    user: {
        read: {
            read_only: number;
            user_id: string;
            admin: number;
            passwd: string;
            realname: string;
        };
        write: {
            read_only: number;
            user_id: string;
            admin: number;
            passwd: string;
            realname: string;
        };
        admin: {
            status: number;
            admin: number;
            fa: number;
            ll: number;
            passwd: string;
        };
    };
    ver: string[];
    cluster: {
        if: unknown[];
    };
    configured: number;
    license: {
        accepted: string;
        key: string;
        rt: number;
        tt: number;
    };
    migrations: number;
    pf: {
        loopback_mappings: unknown[];
        segmentation: {
            status: number;
            from_to: {
                eth0: {
                    eth0: number;
                };
            };
        };
    };
    signatures_version: string;
    website: {
        [key: string]: {
            created: string;
            deleted: unknown;
            name: string;
            updated: string;
        };
    };
}

export declare type TimeConfig = {
    hour: number;
    minute: number;
};

export declare interface TimestampConfig {
    format?: string;
    rule?: string;
}

export declare interface UpdatesScheduleConfig {
    days?: CollectionUpdatesPolicyScheduleDaysConfig;
    time?: CollectionUpdatesPolicyScheduleTimeConfig[];
}

export declare interface UserData {
    customer_name: string;
    email: string;
    first_name: string;
    full_name: string;
    last_name: string;
    user_id: string;
    username: string;
}

export declare interface WhiteListConfigRule {
    cidr?: string;
    port?: string;
    proto?: string;
}

export declare type ZoneMembershipResponse = {
    zoneMembership: ApplianceZoneRecord[];
};

export { }
