"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Project = void 0;
const codegen_csharp_1 = require("@azure-tools/codegen-csharp");
const generator_1 = require("./generator");
const namespace_1 = require("./model/namespace");
const api_class_1 = require("./operation/api-class");
const namespace_2 = require("./operation/namespace");
const namespace_3 = require("./enums/namespace");
class Project extends codegen_csharp_1.Project {
    constructor(service, objectInitializer) {
        super();
        this.service = service;
        this.jsonSerialization = true;
        this.xmlSerialization = false;
        this.defaultPipeline = true;
        this.emitSignals = true;
        this.enableApiRetry = true;
        this.apply(objectInitializer);
    }
    async init(state) {
        var _a, _b;
        await super.init();
        this.state = await new generator_1.State(this.service).init(this);
        if (state) {
            this.state.model = state.model;
        }
        this.apifolder = await this.state.getValue('api-folder', '');
        this.runtimefolder = await this.state.getValue('runtime-folder', 'runtime');
        this.azure = await this.state.getValue('azure', false) || await this.state.getValue('azure-arm', false);
        this.identityCorrection = await this.state.getValue('identity-correction-for-post', this.azure ? true : false);
        this.resourceGroupAppend = await this.state.getValue('resourcegroup-append', this.azure ? true : false);
        this.license = await this.state.getValue('header-text', '');
        this.exportPropertiesForDict = await this.state.getValue('export-properties-for-dict', this.azure ? true : false);
        this.formats = await this.state.getValue('formats', {});
        if (this.azure) {
            this.supportJsonInput = await this.state.getValue('support-json-input', true);
        }
        else {
            this.supportJsonInput = await this.state.getValue('support-json-input', false);
        }
        this.enableApiRetry = await this.state.getValue('enable-api-retry', true);
        // configuration for whether to use fixed array in generated code of model, default is false
        this.fixedArray = await this.state.getValue('fixed-array', false);
        // add project namespace
        this.projectNamespace = (_a = this.state.model.language.csharp) === null || _a === void 0 ? void 0 : _a.namespace;
        this.overrides = {
            'Carbon.Json.Converters': `${this.projectNamespace}.Runtime.Json`,
            'Carbon.Internal.Extensions': `${this.projectNamespace}.Runtime.Json`,
            'Carbon.Internal': `${this.projectNamespace}.Runtime.Json`,
            'Carbon.Json.Parser': `${this.projectNamespace}.Runtime.Json`,
            'Carbon.Data': `${this.projectNamespace}.Runtime.Json`,
            'using Converters;': '',
            'using Internal.Extensions;': '',
            'using Data;': '',
            'using Parser;': '',
            'Carbon.Json': `${this.projectNamespace}.Runtime.Json`,
            'Microsoft.Rest.ClientRuntime': `${this.projectNamespace}.Runtime`,
            'Microsoft.RestClient': `${this.projectNamespace}.${(_b = this.state.model.language.csharp) === null || _b === void 0 ? void 0 : _b.name}`,
            'Microsoft.Rest': this.projectNamespace,
            '#define DICT_PROPERTIES': this.exportPropertiesForDict ? '#define DICT_PROPERTIES' : '#define NO_DICT_PROPERTIES'
        };
        this.serviceNamespace = new namespace_2.ServiceNamespace(this.state);
        this.serviceNamespace.header = this.license;
        this.addNamespace(this.serviceNamespace);
        // add support namespace
        this.supportNamespace = new namespace_3.SupportNamespace(this.serviceNamespace, this.state);
        this.supportNamespace.header = this.license;
        this.addNamespace(this.supportNamespace);
        // add model classes
        this.modelsNamespace = new namespace_1.ModelsNamespace(this.serviceNamespace, this.state.model.schemas, this.state.path('components', 'schemas'));
        this.modelsNamespace.header = this.license;
        this.addNamespace(this.modelsNamespace);
        // create API class
        new api_class_1.ApiClass(this.serviceNamespace, this.state, { description: `Low-level API implementation for the ${this.state.model.info.title} service. \n${this.state.model.info.description || ''}` });
        // abort now if we have any errors.
        this.state.checkpoint();
        return this;
    }
}
exports.Project = Project;
//# sourceMappingURL=project.js.map