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

package azure.resourcemanager.methodsubscriptionid.implementation;

import azure.resourcemanager.methodsubscriptionid.fluent.models.SubscriptionResourceInner;
import azure.resourcemanager.methodsubscriptionid.models.SubscriptionResource;
import azure.resourcemanager.methodsubscriptionid.models.SubscriptionResourceProperties;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;

public final class SubscriptionResourceImpl
    implements SubscriptionResource, SubscriptionResource.Definition, SubscriptionResource.Update {
    private SubscriptionResourceInner innerObject;

    private final azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager serviceManager;

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

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

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

    public SubscriptionResourceProperties properties() {
        return this.innerModel().properties();
    }

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

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

    private azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager manager() {
        return this.serviceManager;
    }

    private String subscriptionId;

    private String subscriptionResourceName;

    public SubscriptionResource create() {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementSubscriptionResourceOperations()
            .putWithResponse(subscriptionId, subscriptionResourceName, this.innerModel(), Context.NONE)
            .getValue();
        return this;
    }

    public SubscriptionResource create(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementSubscriptionResourceOperations()
            .putWithResponse(subscriptionId, subscriptionResourceName, this.innerModel(), context)
            .getValue();
        return this;
    }

    SubscriptionResourceImpl(String name,
        azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager serviceManager) {
        this.innerObject = new SubscriptionResourceInner();
        this.serviceManager = serviceManager;
        this.subscriptionResourceName = name;
    }

    public SubscriptionResourceImpl update() {
        return this;
    }

    public SubscriptionResource apply() {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementSubscriptionResourceOperations()
            .putWithResponse(subscriptionId, subscriptionResourceName, this.innerModel(), Context.NONE)
            .getValue();
        return this;
    }

    public SubscriptionResource apply(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementSubscriptionResourceOperations()
            .putWithResponse(subscriptionId, subscriptionResourceName, this.innerModel(), context)
            .getValue();
        return this;
    }

    SubscriptionResourceImpl(SubscriptionResourceInner innerObject,
        azure.resourcemanager.methodsubscriptionid.MethodSubscriptionIdManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.subscriptionId = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "subscriptions");
        this.subscriptionResourceName
            = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "subscriptionResources");
    }

    public SubscriptionResource refresh() {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementSubscriptionResourceOperations()
            .getWithResponse(subscriptionId, subscriptionResourceName, Context.NONE)
            .getValue();
        return this;
    }

    public SubscriptionResource refresh(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getMixedSubscriptionPlacementSubscriptionResourceOperations()
            .getWithResponse(subscriptionId, subscriptionResourceName, context)
            .getValue();
        return this;
    }

    public SubscriptionResourceImpl withProperties(SubscriptionResourceProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
