/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 * abc
 */

package com.microsoft.azure.management.sql.v2017_10_01_preview.implementation;

import com.microsoft.azure.arm.model.implementation.WrapperImpl;
import com.microsoft.azure.management.sql.v2017_10_01_preview.ManagedDatabaseVulnerabilityAssessmentRuleBaselines;
import com.microsoft.azure.management.sql.v2017_10_01_preview.VulnerabilityAssessmentPolicyBaselineName;
import rx.Observable;
import rx.functions.Func1;
import com.microsoft.azure.management.sql.v2017_10_01_preview.DatabaseVulnerabilityAssessmentRuleBaseline;
import rx.Completable;

class ManagedDatabaseVulnerabilityAssessmentRuleBaselinesImpl extends WrapperImpl<ManagedDatabaseVulnerabilityAssessmentRuleBaselinesInner> implements ManagedDatabaseVulnerabilityAssessmentRuleBaselines {
    private final SqlManager manager;

    ManagedDatabaseVulnerabilityAssessmentRuleBaselinesImpl(SqlManager manager) {
        super(manager.inner().managedDatabaseVulnerabilityAssessmentRuleBaselines());
        this.manager = manager;
    }

    public SqlManager manager() {
        return this.manager;
    }

    @Override
    public DatabaseVulnerabilityAssessmentRuleBaselineImpl defineBaseline(String name) {
        return wrapBaselineModel(name);
    }

    private DatabaseVulnerabilityAssessmentRuleBaselineImpl wrapBaselineModel(String name) {
        return new DatabaseVulnerabilityAssessmentRuleBaselineImpl(name, this.manager());
    }

    private DatabaseVulnerabilityAssessmentRuleBaselineImpl wrapDatabaseVulnerabilityAssessmentRuleBaselineModel(DatabaseVulnerabilityAssessmentRuleBaselineInner inner) {
        return  new DatabaseVulnerabilityAssessmentRuleBaselineImpl(inner, manager());
    }

    private Observable<DatabaseVulnerabilityAssessmentRuleBaselineInner> getDatabaseVulnerabilityAssessmentRuleBaselineInnerUsingManagedDatabaseVulnerabilityAssessmentRuleBaselinesInnerAsync(String id) {
        String resourceGroupName = IdParsingUtils.getValueFromIdByName(id, "resourceGroups");
        String managedInstanceName = IdParsingUtils.getValueFromIdByName(id, "managedInstances");
        String databaseName = IdParsingUtils.getValueFromIdByName(id, "databases");
        String ruleId = IdParsingUtils.getValueFromIdByName(id, "rules");
        VulnerabilityAssessmentPolicyBaselineName baselineName = VulnerabilityAssessmentPolicyBaselineName.valueOf(IdParsingUtils.getValueFromIdByName(id, "baselines"));
        ManagedDatabaseVulnerabilityAssessmentRuleBaselinesInner client = this.inner();
        return client.getAsync(resourceGroupName, managedInstanceName, databaseName, ruleId, baselineName);
    }

    @Override
    public Observable<DatabaseVulnerabilityAssessmentRuleBaseline> getAsync(String resourceGroupName, String managedInstanceName, String databaseName, String ruleId, VulnerabilityAssessmentPolicyBaselineName baselineName) {
        ManagedDatabaseVulnerabilityAssessmentRuleBaselinesInner client = this.inner();
        return client.getAsync(resourceGroupName, managedInstanceName, databaseName, ruleId, baselineName)
        .map(new Func1<DatabaseVulnerabilityAssessmentRuleBaselineInner, DatabaseVulnerabilityAssessmentRuleBaseline>() {
            @Override
            public DatabaseVulnerabilityAssessmentRuleBaseline call(DatabaseVulnerabilityAssessmentRuleBaselineInner inner) {
                return wrapDatabaseVulnerabilityAssessmentRuleBaselineModel(inner);
            }
       });
    }

    @Override
    public Completable deleteAsync(String resourceGroupName, String managedInstanceName, String databaseName, String ruleId, VulnerabilityAssessmentPolicyBaselineName baselineName) {
        ManagedDatabaseVulnerabilityAssessmentRuleBaselinesInner client = this.inner();
        return client.deleteAsync(resourceGroupName, managedInstanceName, databaseName, ruleId, baselineName).toCompletable();
    }

}
