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

package com.azure.resourcemanager.datamigration.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.datamigration.fluent.models.DataMigrationServiceInner;
import com.azure.resourcemanager.datamigration.models.DataMigrationService;
import com.azure.resourcemanager.datamigration.models.DataMigrationServiceStatusResponse;
import com.azure.resourcemanager.datamigration.models.NameAvailabilityRequest;
import com.azure.resourcemanager.datamigration.models.NameAvailabilityResponse;
import com.azure.resourcemanager.datamigration.models.ServiceProvisioningState;
import com.azure.resourcemanager.datamigration.models.ServiceSku;
import java.util.Collections;
import java.util.Map;

public final class DataMigrationServiceImpl
    implements DataMigrationService, DataMigrationService.Definition, DataMigrationService.Update {
    private DataMigrationServiceInner innerObject;

    private final com.azure.resourcemanager.datamigration.DataMigrationManager serviceManager;

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

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

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

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

    public Map<String, String> tags() {
        Map<String, String> inner = this.innerModel().tags();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

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

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

    public ServiceSku sku() {
        return this.innerModel().sku();
    }

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

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

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

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

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

    public String resourceGroupName() {
        return groupName;
    }

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

    private com.azure.resourcemanager.datamigration.DataMigrationManager manager() {
        return this.serviceManager;
    }

    private String groupName;

    private String serviceName;

    public DataMigrationServiceImpl withExistingResourceGroup(String groupName) {
        this.groupName = groupName;
        return this;
    }

    public DataMigrationService create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getServices()
                .createOrUpdate(groupName, serviceName, this.innerModel(), Context.NONE);
        return this;
    }

    public DataMigrationService create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getServices()
                .createOrUpdate(groupName, serviceName, this.innerModel(), context);
        return this;
    }

    DataMigrationServiceImpl(String name, com.azure.resourcemanager.datamigration.DataMigrationManager serviceManager) {
        this.innerObject = new DataMigrationServiceInner();
        this.serviceManager = serviceManager;
        this.serviceName = name;
    }

    public DataMigrationServiceImpl update() {
        return this;
    }

    public DataMigrationService apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getServices()
                .update(groupName, serviceName, this.innerModel(), Context.NONE);
        return this;
    }

    public DataMigrationService apply(Context context) {
        this.innerObject =
            serviceManager.serviceClient().getServices().update(groupName, serviceName, this.innerModel(), context);
        return this;
    }

    DataMigrationServiceImpl(
        DataMigrationServiceInner innerObject,
        com.azure.resourcemanager.datamigration.DataMigrationManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.groupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.serviceName = Utils.getValueFromIdByName(innerObject.id(), "services");
    }

    public DataMigrationService refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getServices()
                .getByResourceGroupWithResponse(groupName, serviceName, Context.NONE)
                .getValue();
        return this;
    }

    public DataMigrationService refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getServices()
                .getByResourceGroupWithResponse(groupName, serviceName, context)
                .getValue();
        return this;
    }

    public Response<DataMigrationServiceStatusResponse> checkStatusWithResponse(Context context) {
        return serviceManager.services().checkStatusWithResponse(groupName, serviceName, context);
    }

    public DataMigrationServiceStatusResponse checkStatus() {
        return serviceManager.services().checkStatus(groupName, serviceName);
    }

    public void start() {
        serviceManager.services().start(groupName, serviceName);
    }

    public void start(Context context) {
        serviceManager.services().start(groupName, serviceName, context);
    }

    public void stop() {
        serviceManager.services().stop(groupName, serviceName);
    }

    public void stop(Context context) {
        serviceManager.services().stop(groupName, serviceName, context);
    }

    public Response<NameAvailabilityResponse> nestedCheckNameAvailabilityWithResponse(
        NameAvailabilityRequest parameters, Context context) {
        return serviceManager
            .services()
            .nestedCheckNameAvailabilityWithResponse(groupName, serviceName, parameters, context);
    }

    public NameAvailabilityResponse nestedCheckNameAvailability(NameAvailabilityRequest parameters) {
        return serviceManager.services().nestedCheckNameAvailability(groupName, serviceName, parameters);
    }

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

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

    public DataMigrationServiceImpl withTags(Map<String, String> tags) {
        this.innerModel().withTags(tags);
        return this;
    }

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

    public DataMigrationServiceImpl withKind(String kind) {
        this.innerModel().withKind(kind);
        return this;
    }

    public DataMigrationServiceImpl withSku(ServiceSku sku) {
        this.innerModel().withSku(sku);
        return this;
    }

    public DataMigrationServiceImpl withPublicKey(String publicKey) {
        this.innerModel().withPublicKey(publicKey);
        return this;
    }

    public DataMigrationServiceImpl withVirtualSubnetId(String virtualSubnetId) {
        this.innerModel().withVirtualSubnetId(virtualSubnetId);
        return this;
    }
}
