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

package com.azure.resourcemanager.chaos.implementation;

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.chaos.fluent.TargetsClient;
import com.azure.resourcemanager.chaos.fluent.models.TargetInner;
import com.azure.resourcemanager.chaos.models.Target;
import com.azure.resourcemanager.chaos.models.Targets;

public final class TargetsImpl implements Targets {
    private static final ClientLogger LOGGER = new ClientLogger(TargetsImpl.class);

    private final TargetsClient innerClient;

    private final com.azure.resourcemanager.chaos.ChaosManager serviceManager;

    public TargetsImpl(TargetsClient innerClient, com.azure.resourcemanager.chaos.ChaosManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public PagedIterable<Target> list(
        String resourceGroupName,
        String parentProviderNamespace,
        String parentResourceType,
        String parentResourceName) {
        PagedIterable<TargetInner> inner =
            this
                .serviceClient()
                .list(resourceGroupName, parentProviderNamespace, parentResourceType, parentResourceName);
        return Utils.mapPage(inner, inner1 -> new TargetImpl(inner1, this.manager()));
    }

    public PagedIterable<Target> list(
        String resourceGroupName,
        String parentProviderNamespace,
        String parentResourceType,
        String parentResourceName,
        String continuationToken,
        Context context) {
        PagedIterable<TargetInner> inner =
            this
                .serviceClient()
                .list(
                    resourceGroupName,
                    parentProviderNamespace,
                    parentResourceType,
                    parentResourceName,
                    continuationToken,
                    context);
        return Utils.mapPage(inner, inner1 -> new TargetImpl(inner1, this.manager()));
    }

    public Response<Target> getWithResponse(
        String resourceGroupName,
        String parentProviderNamespace,
        String parentResourceType,
        String parentResourceName,
        String targetName,
        Context context) {
        Response<TargetInner> inner =
            this
                .serviceClient()
                .getWithResponse(
                    resourceGroupName,
                    parentProviderNamespace,
                    parentResourceType,
                    parentResourceName,
                    targetName,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new TargetImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Target get(
        String resourceGroupName,
        String parentProviderNamespace,
        String parentResourceType,
        String parentResourceName,
        String targetName) {
        TargetInner inner =
            this
                .serviceClient()
                .get(resourceGroupName, parentProviderNamespace, parentResourceType, parentResourceName, targetName);
        if (inner != null) {
            return new TargetImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteWithResponse(
        String resourceGroupName,
        String parentProviderNamespace,
        String parentResourceType,
        String parentResourceName,
        String targetName,
        Context context) {
        return this
            .serviceClient()
            .deleteWithResponse(
                resourceGroupName,
                parentProviderNamespace,
                parentResourceType,
                parentResourceName,
                targetName,
                context);
    }

    public void delete(
        String resourceGroupName,
        String parentProviderNamespace,
        String parentResourceType,
        String parentResourceName,
        String targetName) {
        this
            .serviceClient()
            .delete(resourceGroupName, parentProviderNamespace, parentResourceType, parentResourceName, targetName);
    }

    public Response<Target> createOrUpdateWithResponse(
        String resourceGroupName,
        String parentProviderNamespace,
        String parentResourceType,
        String parentResourceName,
        String targetName,
        TargetInner target,
        Context context) {
        Response<TargetInner> inner =
            this
                .serviceClient()
                .createOrUpdateWithResponse(
                    resourceGroupName,
                    parentProviderNamespace,
                    parentResourceType,
                    parentResourceName,
                    targetName,
                    target,
                    context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new TargetImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Target createOrUpdate(
        String resourceGroupName,
        String parentProviderNamespace,
        String parentResourceType,
        String parentResourceName,
        String targetName,
        TargetInner target) {
        TargetInner inner =
            this
                .serviceClient()
                .createOrUpdate(
                    resourceGroupName,
                    parentProviderNamespace,
                    parentResourceType,
                    parentResourceName,
                    targetName,
                    target);
        if (inner != null) {
            return new TargetImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    private TargetsClient serviceClient() {
        return this.innerClient;
    }

    private com.azure.resourcemanager.chaos.ChaosManager manager() {
        return this.serviceManager;
    }
}
