//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using Pickaxe.Runtime;
using Pickaxe.Runtime.Dom;
using System;
using System.Collections.Generic;
using System.Linq;



public class Code : RuntimeBase
{

    private Scope_678586bbdfa34212b3b96c359a1d8abc _Scope_678586bbdfa34212b3b96c359a1d8abc;

    private Scope_36cf7ef295d14f73ae659d0138686d8f _Scope_36cf7ef295d14f73ae659d0138686d8f;

    public Code(string[] args) :
            base(args)
    {
        _Scope_678586bbdfa34212b3b96c359a1d8abc = new Scope_678586bbdfa34212b3b96c359a1d8abc();
        _Scope_36cf7ef295d14f73ae659d0138686d8f = new Scope_36cf7ef295d14f73ae659d0138686d8f();
        TotalOperations = (TotalOperations + 1);
    }

    public void Run()
    {
        InitProxies();
        Block_b0cca43069ee4c91b79b1e5ddd94de29();
        Step_8ee597a9a4f4401c8f40ef930a8bcf9c();
    }

    public void Block_b0cca43069ee4c91b79b1e5ddd94de29()
    {
        Step_5a9e499dbf4f463e8a3f460e01389e5e();
    }

    private CodeTable<anon_4ffac12ed6584b16899a543ed6d6662c> From_0b0a762c6e4644bdb952952b82e89af5()
    {
        Call(5);
        IEnumerable<anon_4ffac12ed6584b16899a543ed6d6662c> join = Fetch_1f3e4ae495a54eaea2d5dd60e3bf8262();
        CodeTable<anon_4ffac12ed6584b16899a543ed6d6662c> newTable = new CodeTable<anon_4ffac12ed6584b16899a543ed6d6662c>();
        newTable.SetRows(join.ToList());
        return newTable;
    }

    private RuntimeTable<DynamicObject> Download_549a09bb61954a39b172ec64deacf36e()
    {
        Call(5);
        return new DynamicObjectDownloadTable(Pickaxe.Runtime.LazyDownloadArgs.CreateJavaScriptArgs(this, 5, 1, null, 5, "https://www.walmart.com/ip/Gatorade-Variety-Pack-12-Oz-18-Pk/16224470", "\r\n\tvar primaryProductId = __WML_REDUX_INITIAL_STATE__.product.primaryProduct;\r\n\r\n" +
                    "\tvar primaryProduct = __WML_REDUX_INITIAL_STATE__.product.products[primaryProduc" +
                    "tId];\r\n\r\n\treturn [{upc:primaryProduct.upc, url:url}];\r\n"));
    }

    private IEnumerable<anon_4ffac12ed6584b16899a543ed6d6662c> Fetch_1f3e4ae495a54eaea2d5dd60e3bf8262()
    {
        RuntimeTable<DynamicObject> table = Download_549a09bb61954a39b172ec64deacf36e();
        return table.Select(o => {
            return Copy_b61c904ef77340c7a325b94a561002ec(o);
        });
    }

    private anon_4ffac12ed6584b16899a543ed6d6662c Copy_b61c904ef77340c7a325b94a561002ec(DynamicObject o)
    {
        anon_4ffac12ed6584b16899a543ed6d6662c t = new anon_4ffac12ed6584b16899a543ed6d6662c();
        t.DynamicObject = o;
        return t;
    }

    private Table<ResultRow> Select_43e9593ca897423489a7897dfe7490df()
    {
        Call(4);
        RuntimeTable<ResultRow> result = new RuntimeTable<ResultRow>();
        result.AddColumn("upc");
        result.AddColumn("url");
        CodeTable<anon_4ffac12ed6584b16899a543ed6d6662c> fromTable = From_0b0a762c6e4644bdb952952b82e89af5();
        IEnumerator<anon_4ffac12ed6584b16899a543ed6d6662c> x = fromTable.GetEnumerator();
        for (
        ; x.MoveNext();
        )
        {
            anon_4ffac12ed6584b16899a543ed6d6662c row = x.Current;
            ResultRow resultRow = new ResultRow(2);
            resultRow[0] = row.DynamicObject["upc"];
            resultRow[1] = row.DynamicObject["url"];
            result.Add(resultRow);
        }
        OnSelect(result);
        return result;
    }

    public void Step_5a9e499dbf4f463e8a3f460e01389e5e()
    {
        Select_43e9593ca897423489a7897dfe7490df();
        OnProgress();
    }

    public void Step_8ee597a9a4f4401c8f40ef930a8bcf9c()
    {
        OnProgress(new ProgressArgs(TotalOperations, TotalOperations));
    }

    private class Scope_678586bbdfa34212b3b96c359a1d8abc
    {

        public int g_identity;

        public Scope_678586bbdfa34212b3b96c359a1d8abc()
        {
        }
    }

    private class Scope_36cf7ef295d14f73ae659d0138686d8f
    {

        public Scope_36cf7ef295d14f73ae659d0138686d8f()
        {
        }
    }

    private class anon_4ffac12ed6584b16899a543ed6d6662c : IRow
    {

        public DynamicObject DynamicObject;
    }
}