//!!! DO NOT EDIT THIS FILE, IT IS AUTO-GENERATED !!!//

import { Agent } from '../../Agent/Agent.class';
import { createSafeAccessor } from '../utils';
import { ComponentWrapper } from '../ComponentWrapper.class';
import { InputSettings, ComponentInput } from '../../types/SDKTypes';

export interface TScrapflyWebScrapeSettings {
    name?: string;
    /** Enable Anti-Scraping Protection */
    antiScrapingProtection?: boolean;
    /** Enable JavaScript Rendering */
    javascriptRendering?: boolean;
    /** Enable Auto Scroll */
    autoScroll?: boolean;
    /** Format */
    format?: string;
    /** Countries */
    countries?: any[];
}

export type TScrapflyWebScrapeInputs = {
    /** The URLs to scrape */
    URLs?: any[];
    [key: string]: any;
};

export type TScrapflyWebScrapeOutputs = {
    /** The scraped results */
    Results: any;
    /** The URLs that failed to scrape */
    FailedURLs: any;
    [key: string]: any;
};

/**
 * Use this component to scrape web pages
 */
export function ScrapflyWebScrape(settings?: TScrapflyWebScrapeSettings, agent?: Agent) {    
    //const { name, ...settingsWithoutName } = settings || {};
    const dataObject: any = { 
        name: /*settings?.name || */'ScrapflyWebScrape', 
        settings: {
            //...settingsWithoutName 
            ...settings
        }
    };
    const component = new ComponentWrapper(dataObject, agent);

    if (agent) {
        (agent.structure.components as ComponentWrapper[]).push(component);
        agent.sync();
    }
    
    const _out: TScrapflyWebScrapeOutputs = createSafeAccessor({
        Results: createSafeAccessor({}, component, 'Results', {"type":"Array","description":"The scraped results","default":true}),
        FailedURLs: createSafeAccessor({}, component, 'FailedURLs', {"type":"Array","description":"The URLs that failed to scrape","default":true}),
    }, component, '');

    const _in: { [key: string]: ComponentInput } = {
        URLs: {
            component,
            type: 'Array',
            optional: false,
            default: true,
        },
    };

    dataObject.outputs = _out;
    dataObject.inputs = _in;

    component.inputs(_in);

    const wrapper = {
        /** Component outputs - access via .out.OutputName */
        out: _out,        

        /** 
         * Create or Connect the component inputs 
         * if the input does not exist, it will be created
         * @examples 
         *    - component.in({ Input: source.out.data })
         *    - component.in({ Input: { type: 'string', source:source.out.data } })
         */        
        in: component.inputs.bind(component) as (inputs: TScrapflyWebScrapeInputs) => void,
    };

    return wrapper;
}
