"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addImport = void 0;
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
const ts = require("typescript");
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
const change_1 = require("@schematics/angular/utility/change");
const strings_1 = require("@angular-devkit/core/src/utils/strings");
class AddToModuleContext {
}
const addImport = (tree, _options) => {
    //// Importing Feature module
    let featureName;
    let featurePath;
    if (_options.dappDemo == "minimalContract") {
        featureName = `${(0, strings_1.capitalize)(_options.contractName)}Module`;
        featurePath =
            `./${(0, strings_1.dasherize)(_options.contractName)}/${(0, strings_1.dasherize)(_options.contractName)}.module`;
    }
    else if (_options.dappDemo == "helloWorldContract") {
        featureName = "HelloWorldContractModule";
        featurePath =
            "./1-hello-world-contract/hello-world-contract.module";
    }
    else if (_options.dappDemo == "debugContract") {
        featureName = "DebugContractModule";
        featurePath = "./2-debug-contract/debug-contract.module";
    }
    else if (_options.dappDemo == "nftContract") {
        featureName = "NftContractModule";
        featurePath = "./3-nft-contract/nft-contract.module";
    }
    else if (_options.dappDemo == "lensProtocol") {
        featureName = "LensProtocolModule";
        featurePath = "./4-lens-protocol/lens-protocol.module";
    }
    else if (_options.dappDemo == "theGraph") {
        featureName = "TheGraphDemoModule";
        featurePath = "./5-the-graph/the-graph-demo.module";
    }
    else if (_options.dappDemo == "superFluid") {
        featureName = "SuperFluidDemoModule";
        featurePath = "./6-super-fluid/super-fluid-demo.module";
    }
    else {
        return tree;
    }
    const appModulePath = `/${_options.sourceRoot}/app/app.module.ts`;
    const appModuleFile = tree.read((0, core_1.normalize)(appModulePath)).toString("utf-8");
    if (!appModuleFile) {
        throw new schematics_1.SchematicsException("app.module.ts not found");
    }
    // const result = new AddToModuleContext();
    const source_app = ts.createSourceFile(appModulePath, appModuleFile, ts.ScriptTarget.Latest, true);
    console.log(featureName);
    console.log(featurePath);
    let importsFeature = []; //=  addImportToModule(
    //   source_app,
    //   appModulePath,
    //   featureName,
    //   featurePath,
    // )
    const importReducer = (0, ast_utils_1.insertImport)(source_app, appModulePath, "we3ReducerFunction", "angular-web3");
    const importStore = (0, ast_utils_1.addImportToModule)(source_app, appModulePath, 'StoreModule.forRoot({web3: we3ReducerFunction}),', '@ngrx/store');
    const importDappInjector = (0, ast_utils_1.addImportToModule)(source_app, appModulePath, "DappInjectorModule.forRoot({wallet:'local', defaultNetwork:'localhost'})", "./dapp-injector/dapp-injector.module");
    // const importProvider:Change[] = addProviderToModule(
    //   source_app,
    //   appModulePath,
    //   'blockchain_providers',
    //   './blockchain_wiring'
    // )
    // ============ Manual Angular Material installation  ========================
    if (_options.demoToInstall == true) {
        const importDappBrowserAnimations = (0, ast_utils_1.addImportToModule)(source_app, appModulePath, 'BrowserAnimationsModule', '@angular/platform-browser/animations');
        importsFeature = importsFeature.concat(importDappBrowserAnimations);
    }
    const importRecorder = tree.beginUpdate(appModulePath);
    for (const change of importsFeature.concat(importDappInjector, importStore, [importReducer])) {
        if (change instanceof change_1.InsertChange) {
            importRecorder.insertLeft(change.pos, change.toAdd);
        }
    }
    tree.commitUpdate(importRecorder);
    return tree;
};
exports.addImport = addImport;
//# sourceMappingURL=addImportStatement.js.map