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

package com.azure.resourcemanager.relay.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.relay.fluent.models.WcfRelayInner;
import com.azure.resourcemanager.relay.models.Relaytype;
import com.azure.resourcemanager.relay.models.WcfRelay;
import java.time.OffsetDateTime;

public final class WcfRelayImpl implements WcfRelay, WcfRelay.Definition, WcfRelay.Update {
    private WcfRelayInner innerObject;

    private final com.azure.resourcemanager.relay.RelayManager serviceManager;

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

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

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

    public Boolean isDynamic() {
        return this.innerModel().isDynamic();
    }

    public OffsetDateTime createdAt() {
        return this.innerModel().createdAt();
    }

    public OffsetDateTime updatedAt() {
        return this.innerModel().updatedAt();
    }

    public Integer listenerCount() {
        return this.innerModel().listenerCount();
    }

    public Relaytype relayType() {
        return this.innerModel().relayType();
    }

    public Boolean requiresClientAuthorization() {
        return this.innerModel().requiresClientAuthorization();
    }

    public Boolean requiresTransportSecurity() {
        return this.innerModel().requiresTransportSecurity();
    }

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.relay.RelayManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String namespaceName;

    private String relayName;

    public WcfRelayImpl withExistingNamespace(String resourceGroupName, String namespaceName) {
        this.resourceGroupName = resourceGroupName;
        this.namespaceName = namespaceName;
        return this;
    }

    public WcfRelay create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWcfRelays()
                .createOrUpdateWithResponse(
                    resourceGroupName, namespaceName, relayName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public WcfRelay create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWcfRelays()
                .createOrUpdateWithResponse(resourceGroupName, namespaceName, relayName, this.innerModel(), context)
                .getValue();
        return this;
    }

    WcfRelayImpl(String name, com.azure.resourcemanager.relay.RelayManager serviceManager) {
        this.innerObject = new WcfRelayInner();
        this.serviceManager = serviceManager;
        this.relayName = name;
    }

    public WcfRelayImpl update() {
        return this;
    }

    public WcfRelay apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWcfRelays()
                .createOrUpdateWithResponse(
                    resourceGroupName, namespaceName, relayName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public WcfRelay apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWcfRelays()
                .createOrUpdateWithResponse(resourceGroupName, namespaceName, relayName, this.innerModel(), context)
                .getValue();
        return this;
    }

    WcfRelayImpl(WcfRelayInner innerObject, com.azure.resourcemanager.relay.RelayManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.namespaceName = Utils.getValueFromIdByName(innerObject.id(), "namespaces");
        this.relayName = Utils.getValueFromIdByName(innerObject.id(), "wcfRelays");
    }

    public WcfRelay refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWcfRelays()
                .getWithResponse(resourceGroupName, namespaceName, relayName, Context.NONE)
                .getValue();
        return this;
    }

    public WcfRelay refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWcfRelays()
                .getWithResponse(resourceGroupName, namespaceName, relayName, context)
                .getValue();
        return this;
    }

    public WcfRelayImpl withRelayType(Relaytype relayType) {
        this.innerModel().withRelayType(relayType);
        return this;
    }

    public WcfRelayImpl withRequiresClientAuthorization(Boolean requiresClientAuthorization) {
        this.innerModel().withRequiresClientAuthorization(requiresClientAuthorization);
        return this;
    }

    public WcfRelayImpl withRequiresTransportSecurity(Boolean requiresTransportSecurity) {
        this.innerModel().withRequiresTransportSecurity(requiresTransportSecurity);
        return this;
    }

    public WcfRelayImpl withUserMetadata(String userMetadata) {
        this.innerModel().withUserMetadata(userMetadata);
        return this;
    }
}
