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

package com.azure.resourcemanager.storagemover.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.storagemover.fluent.models.EndpointInner;
import com.azure.resourcemanager.storagemover.models.Endpoint;
import com.azure.resourcemanager.storagemover.models.EndpointBaseProperties;
import com.azure.resourcemanager.storagemover.models.EndpointBaseUpdateParameters;
import com.azure.resourcemanager.storagemover.models.EndpointBaseUpdateProperties;

public final class EndpointImpl implements Endpoint, Endpoint.Definition, Endpoint.Update {
    private EndpointInner innerObject;

    private final com.azure.resourcemanager.storagemover.StorageMoverManager serviceManager;

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.storagemover.StorageMoverManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String storageMoverName;

    private String endpointName;

    private EndpointBaseUpdateParameters updateEndpointParam;

    public EndpointImpl withExistingStorageMover(String resourceGroupName, String storageMoverName) {
        this.resourceGroupName = resourceGroupName;
        this.storageMoverName = storageMoverName;
        return this;
    }

    public Endpoint create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getEndpoints()
                .createOrUpdateWithResponse(
                    resourceGroupName, storageMoverName, endpointName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Endpoint create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getEndpoints()
                .createOrUpdateWithResponse(
                    resourceGroupName, storageMoverName, endpointName, this.innerModel(), context)
                .getValue();
        return this;
    }

    EndpointImpl(String name, com.azure.resourcemanager.storagemover.StorageMoverManager serviceManager) {
        this.innerObject = new EndpointInner();
        this.serviceManager = serviceManager;
        this.endpointName = name;
    }

    public EndpointImpl update() {
        this.updateEndpointParam = new EndpointBaseUpdateParameters();
        return this;
    }

    public Endpoint apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getEndpoints()
                .updateWithResponse(
                    resourceGroupName, storageMoverName, endpointName, updateEndpointParam, Context.NONE)
                .getValue();
        return this;
    }

    public Endpoint apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getEndpoints()
                .updateWithResponse(resourceGroupName, storageMoverName, endpointName, updateEndpointParam, context)
                .getValue();
        return this;
    }

    EndpointImpl(EndpointInner innerObject, com.azure.resourcemanager.storagemover.StorageMoverManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.storageMoverName = Utils.getValueFromIdByName(innerObject.id(), "storageMovers");
        this.endpointName = Utils.getValueFromIdByName(innerObject.id(), "endpoints");
    }

    public Endpoint refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getEndpoints()
                .getWithResponse(resourceGroupName, storageMoverName, endpointName, Context.NONE)
                .getValue();
        return this;
    }

    public Endpoint refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getEndpoints()
                .getWithResponse(resourceGroupName, storageMoverName, endpointName, context)
                .getValue();
        return this;
    }

    public EndpointImpl withProperties(EndpointBaseProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }

    public EndpointImpl withProperties(EndpointBaseUpdateProperties properties) {
        this.updateEndpointParam.withProperties(properties);
        return this;
    }
}
