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

package com.azure.resourcemanager.billing.implementation;

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.billing.fluent.PoliciesClient;
import com.azure.resourcemanager.billing.fluent.models.CustomerPolicyInner;
import com.azure.resourcemanager.billing.fluent.models.PolicyInner;
import com.azure.resourcemanager.billing.models.CustomerPolicy;
import com.azure.resourcemanager.billing.models.Policies;
import com.azure.resourcemanager.billing.models.Policy;

public final class PoliciesImpl implements Policies {
    private static final ClientLogger LOGGER = new ClientLogger(PoliciesImpl.class);

    private final PoliciesClient innerClient;

    private final com.azure.resourcemanager.billing.BillingManager serviceManager;

    public PoliciesImpl(PoliciesClient innerClient, com.azure.resourcemanager.billing.BillingManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<Policy> getByBillingProfileWithResponse(
        String billingAccountName, String billingProfileName, Context context) {
        Response<PolicyInner> inner =
            this.serviceClient().getByBillingProfileWithResponse(billingAccountName, billingProfileName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new PolicyImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Policy getByBillingProfile(String billingAccountName, String billingProfileName) {
        PolicyInner inner = this.serviceClient().getByBillingProfile(billingAccountName, billingProfileName);
        if (inner != null) {
            return new PolicyImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Policy> updateWithResponse(
        String billingAccountName, String billingProfileName, PolicyInner parameters, Context context) {
        Response<PolicyInner> inner =
            this.serviceClient().updateWithResponse(billingAccountName, billingProfileName, parameters, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new PolicyImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public Policy update(String billingAccountName, String billingProfileName, PolicyInner parameters) {
        PolicyInner inner = this.serviceClient().update(billingAccountName, billingProfileName, parameters);
        if (inner != null) {
            return new PolicyImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<CustomerPolicy> getByCustomerWithResponse(
        String billingAccountName, String customerName, Context context) {
        Response<CustomerPolicyInner> inner =
            this.serviceClient().getByCustomerWithResponse(billingAccountName, customerName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new CustomerPolicyImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public CustomerPolicy getByCustomer(String billingAccountName, String customerName) {
        CustomerPolicyInner inner = this.serviceClient().getByCustomer(billingAccountName, customerName);
        if (inner != null) {
            return new CustomerPolicyImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<CustomerPolicy> updateCustomerWithResponse(
        String billingAccountName, String customerName, CustomerPolicyInner parameters, Context context) {
        Response<CustomerPolicyInner> inner =
            this.serviceClient().updateCustomerWithResponse(billingAccountName, customerName, parameters, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new CustomerPolicyImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public CustomerPolicy updateCustomer(
        String billingAccountName, String customerName, CustomerPolicyInner parameters) {
        CustomerPolicyInner inner = this.serviceClient().updateCustomer(billingAccountName, customerName, parameters);
        if (inner != null) {
            return new CustomerPolicyImpl(inner, this.manager());
        } else {
            return null;
        }
    }

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

    private com.azure.resourcemanager.billing.BillingManager manager() {
        return this.serviceManager;
    }
}
