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

package com.azure.resourcemanager.devtestlabs.implementation;

import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.devtestlabs.fluent.models.LabCostInner;
import com.azure.resourcemanager.devtestlabs.models.LabCost;
import com.azure.resourcemanager.devtestlabs.models.LabCostDetailsProperties;
import com.azure.resourcemanager.devtestlabs.models.LabCostSummaryProperties;
import com.azure.resourcemanager.devtestlabs.models.LabResourceCostProperties;
import com.azure.resourcemanager.devtestlabs.models.TargetCostProperties;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class LabCostImpl implements LabCost, LabCost.Definition, LabCost.Update {
    private LabCostInner innerObject;

    private final com.azure.resourcemanager.devtestlabs.DevTestLabsManager 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 TargetCostProperties targetCost() {
        return this.innerModel().targetCost();
    }

    public LabCostSummaryProperties labCostSummary() {
        return this.innerModel().labCostSummary();
    }

    public List<LabCostDetailsProperties> labCostDetails() {
        List<LabCostDetailsProperties> inner = this.innerModel().labCostDetails();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public List<LabResourceCostProperties> resourceCosts() {
        List<LabResourceCostProperties> inner = this.innerModel().resourceCosts();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

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

    public OffsetDateTime startDateTime() {
        return this.innerModel().startDateTime();
    }

    public OffsetDateTime endDateTime() {
        return this.innerModel().endDateTime();
    }

    public OffsetDateTime createdDate() {
        return this.innerModel().createdDate();
    }

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.devtestlabs.DevTestLabsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String labName;

    private String name;

    public LabCostImpl withExistingLab(String resourceGroupName, String labName) {
        this.resourceGroupName = resourceGroupName;
        this.labName = labName;
        return this;
    }

    public LabCost create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCosts()
                .createOrUpdateWithResponse(resourceGroupName, labName, name, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public LabCost create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCosts()
                .createOrUpdateWithResponse(resourceGroupName, labName, name, this.innerModel(), context)
                .getValue();
        return this;
    }

    LabCostImpl(String name, com.azure.resourcemanager.devtestlabs.DevTestLabsManager serviceManager) {
        this.innerObject = new LabCostInner();
        this.serviceManager = serviceManager;
        this.name = name;
    }

    public LabCostImpl update() {
        return this;
    }

    public LabCost apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCosts()
                .createOrUpdateWithResponse(resourceGroupName, labName, name, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public LabCost apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCosts()
                .createOrUpdateWithResponse(resourceGroupName, labName, name, this.innerModel(), context)
                .getValue();
        return this;
    }

    LabCostImpl(LabCostInner innerObject, com.azure.resourcemanager.devtestlabs.DevTestLabsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.labName = Utils.getValueFromIdByName(innerObject.id(), "labs");
        this.name = Utils.getValueFromIdByName(innerObject.id(), "costs");
    }

    public LabCost refresh() {
        String localExpand = null;
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCosts()
                .getWithResponse(resourceGroupName, labName, name, localExpand, Context.NONE)
                .getValue();
        return this;
    }

    public LabCost refresh(Context context) {
        String localExpand = null;
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCosts()
                .getWithResponse(resourceGroupName, labName, name, localExpand, context)
                .getValue();
        return this;
    }

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

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

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

    public LabCostImpl withTargetCost(TargetCostProperties targetCost) {
        this.innerModel().withTargetCost(targetCost);
        return this;
    }

    public LabCostImpl withCurrencyCode(String currencyCode) {
        this.innerModel().withCurrencyCode(currencyCode);
        return this;
    }

    public LabCostImpl withStartDateTime(OffsetDateTime startDateTime) {
        this.innerModel().withStartDateTime(startDateTime);
        return this;
    }

    public LabCostImpl withEndDateTime(OffsetDateTime endDateTime) {
        this.innerModel().withEndDateTime(endDateTime);
        return this;
    }

    public LabCostImpl withCreatedDate(OffsetDateTime createdDate) {
        this.innerModel().withCreatedDate(createdDate);
        return this;
    }
}
