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

package com.azure.resourcemanager.recoveryservicessiterecovery.implementation;

import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.recoveryservicessiterecovery.fluent.models.FabricInner;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.Fabric;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.FabricCreationInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.FabricCreationInputProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.FabricProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.FailoverProcessServerRequest;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RenewCertificateInput;

public final class FabricImpl implements Fabric, Fabric.Definition {
    private FabricInner innerObject;

    private final com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager;

    FabricImpl(
        FabricInner innerObject,
        com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
    }

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

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

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

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

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

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

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

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

    private com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager manager() {
        return this.serviceManager;
    }

    private String resourceName;

    private String resourceGroupName;

    private String fabricName;

    private FabricCreationInput createInput;

    public FabricImpl withExistingVault(String resourceName, String resourceGroupName) {
        this.resourceName = resourceName;
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public Fabric create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationFabrics()
                .create(resourceName, resourceGroupName, fabricName, createInput, Context.NONE);
        return this;
    }

    public Fabric create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationFabrics()
                .create(resourceName, resourceGroupName, fabricName, createInput, context);
        return this;
    }

    FabricImpl(String name, com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = new FabricInner();
        this.serviceManager = serviceManager;
        this.fabricName = name;
        this.createInput = new FabricCreationInput();
    }

    public Fabric refresh() {
        String localFilter = null;
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationFabrics()
                .getWithResponse(resourceName, resourceGroupName, fabricName, localFilter, Context.NONE)
                .getValue();
        return this;
    }

    public Fabric refresh(Context context) {
        String localFilter = null;
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationFabrics()
                .getWithResponse(resourceName, resourceGroupName, fabricName, localFilter, context)
                .getValue();
        return this;
    }

    public Fabric checkConsistency() {
        return serviceManager.replicationFabrics().checkConsistency(resourceName, resourceGroupName, fabricName);
    }

    public Fabric checkConsistency(Context context) {
        return serviceManager
            .replicationFabrics()
            .checkConsistency(resourceName, resourceGroupName, fabricName, context);
    }

    public void migrateToAad() {
        serviceManager.replicationFabrics().migrateToAad(resourceName, resourceGroupName, fabricName);
    }

    public void migrateToAad(Context context) {
        serviceManager.replicationFabrics().migrateToAad(resourceName, resourceGroupName, fabricName, context);
    }

    public Fabric reassociateGateway(FailoverProcessServerRequest failoverProcessServerRequest) {
        return serviceManager
            .replicationFabrics()
            .reassociateGateway(resourceName, resourceGroupName, fabricName, failoverProcessServerRequest);
    }

    public Fabric reassociateGateway(FailoverProcessServerRequest failoverProcessServerRequest, Context context) {
        return serviceManager
            .replicationFabrics()
            .reassociateGateway(resourceName, resourceGroupName, fabricName, failoverProcessServerRequest, context);
    }

    public void delete() {
        serviceManager.replicationFabrics().delete(resourceName, resourceGroupName, fabricName);
    }

    public void delete(Context context) {
        serviceManager.replicationFabrics().delete(resourceName, resourceGroupName, fabricName, context);
    }

    public Fabric renewCertificate(RenewCertificateInput renewCertificate) {
        return serviceManager
            .replicationFabrics()
            .renewCertificate(resourceName, resourceGroupName, fabricName, renewCertificate);
    }

    public Fabric renewCertificate(RenewCertificateInput renewCertificate, Context context) {
        return serviceManager
            .replicationFabrics()
            .renewCertificate(resourceName, resourceGroupName, fabricName, renewCertificate, context);
    }

    public FabricImpl withProperties(FabricCreationInputProperties properties) {
        this.createInput.withProperties(properties);
        return this;
    }
}
