// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.hybridnetwork.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.hybridnetwork.fluent.models.PreviewSubscriptionInner;
import com.azure.resourcemanager.hybridnetwork.models.PreviewSubscription;
import com.azure.resourcemanager.hybridnetwork.models.ProvisioningState;

public final class PreviewSubscriptionImpl
    implements PreviewSubscription, PreviewSubscription.Definition, PreviewSubscription.Update {
    private PreviewSubscriptionInner innerObject;

    private final com.azure.resourcemanager.hybridnetwork.HybridNetworkManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

    public ProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public PreviewSubscriptionInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.hybridnetwork.HybridNetworkManager manager() {
        return this.serviceManager;
    }

    private String vendorName;

    private String skuName;

    private String previewSubscription;

    public PreviewSubscriptionImpl withExistingVendorSku(String vendorName, String skuName) {
        this.vendorName = vendorName;
        this.skuName = skuName;
        return this;
    }

    public PreviewSubscription create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVendorSkuPreviews()
                .createOrUpdate(vendorName, skuName, previewSubscription, this.innerModel(), Context.NONE);
        return this;
    }

    public PreviewSubscription create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVendorSkuPreviews()
                .createOrUpdate(vendorName, skuName, previewSubscription, this.innerModel(), context);
        return this;
    }

    PreviewSubscriptionImpl(String name, com.azure.resourcemanager.hybridnetwork.HybridNetworkManager serviceManager) {
        this.innerObject = new PreviewSubscriptionInner();
        this.serviceManager = serviceManager;
        this.previewSubscription = name;
    }

    public PreviewSubscriptionImpl update() {
        return this;
    }

    public PreviewSubscription apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVendorSkuPreviews()
                .createOrUpdate(vendorName, skuName, previewSubscription, this.innerModel(), Context.NONE);
        return this;
    }

    public PreviewSubscription apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVendorSkuPreviews()
                .createOrUpdate(vendorName, skuName, previewSubscription, this.innerModel(), context);
        return this;
    }

    PreviewSubscriptionImpl(
        PreviewSubscriptionInner innerObject,
        com.azure.resourcemanager.hybridnetwork.HybridNetworkManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.vendorName = Utils.getValueFromIdByName(innerObject.id(), "vendors");
        this.skuName = Utils.getValueFromIdByName(innerObject.id(), "vendorSkus");
        this.previewSubscription = Utils.getValueFromIdByName(innerObject.id(), "previewSubscriptions");
    }

    public PreviewSubscription refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVendorSkuPreviews()
                .getWithResponse(vendorName, skuName, previewSubscription, Context.NONE)
                .getValue();
        return this;
    }

    public PreviewSubscription refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getVendorSkuPreviews()
                .getWithResponse(vendorName, skuName, previewSubscription, context)
                .getValue();
        return this;
    }
}
