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

package com.azure.resourcemanager.healthcareapis.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.healthcareapis.fluent.models.IotFhirDestinationInner;
import com.azure.resourcemanager.healthcareapis.models.IotFhirDestination;
import com.azure.resourcemanager.healthcareapis.models.IotIdentityResolutionType;
import com.azure.resourcemanager.healthcareapis.models.IotMappingProperties;

public final class IotFhirDestinationImpl
    implements IotFhirDestination, IotFhirDestination.Definition, IotFhirDestination.Update {
    private IotFhirDestinationInner innerObject;

    private final com.azure.resourcemanager.healthcareapis.HealthcareApisManager serviceManager;

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

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

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

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

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

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

    public IotIdentityResolutionType resourceIdentityResolutionType() {
        return this.innerModel().resourceIdentityResolutionType();
    }

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

    public IotMappingProperties fhirMapping() {
        return this.innerModel().fhirMapping();
    }

    public Region region() {
        return Region.fromName(this.regionName());
    }

    public String regionName() {
        return this.location();
    }

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

    private com.azure.resourcemanager.healthcareapis.HealthcareApisManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String workspaceName;

    private String iotConnectorName;

    private String fhirDestinationName;

    public IotFhirDestinationImpl withExistingIotconnector(
        String resourceGroupName, String workspaceName, String iotConnectorName) {
        this.resourceGroupName = resourceGroupName;
        this.workspaceName = workspaceName;
        this.iotConnectorName = iotConnectorName;
        return this;
    }

    public IotFhirDestination create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIotConnectorFhirDestinations()
                .createOrUpdate(
                    resourceGroupName,
                    workspaceName,
                    iotConnectorName,
                    fhirDestinationName,
                    this.innerModel(),
                    Context.NONE);
        return this;
    }

    public IotFhirDestination create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIotConnectorFhirDestinations()
                .createOrUpdate(
                    resourceGroupName,
                    workspaceName,
                    iotConnectorName,
                    fhirDestinationName,
                    this.innerModel(),
                    context);
        return this;
    }

    IotFhirDestinationImpl(String name, com.azure.resourcemanager.healthcareapis.HealthcareApisManager serviceManager) {
        this.innerObject = new IotFhirDestinationInner();
        this.serviceManager = serviceManager;
        this.fhirDestinationName = name;
    }

    public IotFhirDestinationImpl update() {
        return this;
    }

    public IotFhirDestination apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIotConnectorFhirDestinations()
                .createOrUpdate(
                    resourceGroupName,
                    workspaceName,
                    iotConnectorName,
                    fhirDestinationName,
                    this.innerModel(),
                    Context.NONE);
        return this;
    }

    public IotFhirDestination apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIotConnectorFhirDestinations()
                .createOrUpdate(
                    resourceGroupName,
                    workspaceName,
                    iotConnectorName,
                    fhirDestinationName,
                    this.innerModel(),
                    context);
        return this;
    }

    IotFhirDestinationImpl(
        IotFhirDestinationInner innerObject,
        com.azure.resourcemanager.healthcareapis.HealthcareApisManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.workspaceName = Utils.getValueFromIdByName(innerObject.id(), "workspaces");
        this.iotConnectorName = Utils.getValueFromIdByName(innerObject.id(), "iotconnectors");
        this.fhirDestinationName = Utils.getValueFromIdByName(innerObject.id(), "fhirdestinations");
    }

    public IotFhirDestination refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIotConnectorFhirDestinations()
                .getWithResponse(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, Context.NONE)
                .getValue();
        return this;
    }

    public IotFhirDestination refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getIotConnectorFhirDestinations()
                .getWithResponse(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, context)
                .getValue();
        return this;
    }

    public IotFhirDestinationImpl withResourceIdentityResolutionType(
        IotIdentityResolutionType resourceIdentityResolutionType) {
        this.innerModel().withResourceIdentityResolutionType(resourceIdentityResolutionType);
        return this;
    }

    public IotFhirDestinationImpl withFhirServiceResourceId(String fhirServiceResourceId) {
        this.innerModel().withFhirServiceResourceId(fhirServiceResourceId);
        return this;
    }

    public IotFhirDestinationImpl withFhirMapping(IotMappingProperties fhirMapping) {
        this.innerModel().withFhirMapping(fhirMapping);
        return this;
    }

    public IotFhirDestinationImpl withRegion(Region location) {
        this.innerModel().withLocation(location.toString());
        return this;
    }

    public IotFhirDestinationImpl withRegion(String location) {
        this.innerModel().withLocation(location);
        return this;
    }

    public IotFhirDestinationImpl withEtag(String etag) {
        this.innerModel().withEtag(etag);
        return this;
    }
}
