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

package azure.versioning.previewversion;

import azure.versioning.previewversion.implementation.JsonMergePatchHelper;
import azure.versioning.previewversion.implementation.PreviewVersionClientImpl;
import azure.versioning.previewversion.models.ListWidgetsResponse;
import azure.versioning.previewversion.models.UpdateWidgetColorRequest;
import azure.versioning.previewversion.models.Widget;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;

/**
 * Initializes a new instance of the synchronous PreviewVersionClient type.
 */
@ServiceClient(builder = PreviewVersionClientBuilder.class)
public final class PreviewVersionClient {
    @Generated
    private final PreviewVersionClientImpl serviceClient;

    /**
     * Initializes an instance of PreviewVersionClient class.
     * 
     * @param serviceClient the service client implementation.
     */
    @Generated
    PreviewVersionClient(PreviewVersionClientImpl serviceClient) {
        this.serviceClient = serviceClient;
    }

    /**
     * Get widget by id (available in all versions).
     * <p><strong>Response Body Schema</strong></p>
     * 
     * <pre>
     * {@code
     * {
     *     id: String (Required)
     *     name: String (Required)
     *     color: String (Optional)
     * }
     * }
     * </pre>
     * 
     * @param id The id parameter.
     * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @return widget by id (available in all versions) along with {@link Response}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<BinaryData> getWidgetWithResponse(String id, RequestOptions requestOptions) {
        return this.serviceClient.getWidgetWithResponse(id, requestOptions);
    }

    /**
     * Update widget color (preview only).
     * <p><strong>Request Body Schema</strong></p>
     * 
     * <pre>
     * {@code
     * {
     *     color: String (Optional, Required on create)
     * }
     * }
     * </pre>
     * 
     * <p><strong>Response Body Schema</strong></p>
     * 
     * <pre>
     * {@code
     * {
     *     id: String (Required)
     *     name: String (Required)
     *     color: String (Optional)
     * }
     * }
     * </pre>
     * 
     * @param id The id parameter.
     * @param colorUpdate The colorUpdate parameter.
     * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @return a simple model for testing along with {@link Response}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<BinaryData> updateWidgetColorWithResponse(String id, BinaryData colorUpdate,
        RequestOptions requestOptions) {
        return this.serviceClient.updateWidgetColorWithResponse(id, colorUpdate, requestOptions);
    }

    /**
     * List widgets with optional color filtering.
     * <p><strong>Query Parameters</strong></p>
     * <table border="1">
     * <caption>Query Parameters</caption>
     * <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
     * <tr><td>name</td><td>String</td><td>No</td><td>The name parameter</td></tr>
     * <tr><td>color</td><td>String</td><td>No</td><td>The color parameter</td></tr>
     * </table>
     * You can add these to a request with {@link RequestOptions#addQueryParam}
     * <p><strong>Response Body Schema</strong></p>
     * 
     * <pre>
     * {@code
     * {
     *     widgets (Required): [
     *          (Required){
     *             id: String (Required)
     *             name: String (Required)
     *             color: String (Optional)
     *         }
     *     ]
     * }
     * }
     * </pre>
     * 
     * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @return the response body along with {@link Response}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<BinaryData> listWidgetsWithResponse(RequestOptions requestOptions) {
        return this.serviceClient.listWidgetsWithResponse(requestOptions);
    }

    /**
     * Get widget by id (available in all versions).
     * 
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return widget by id (available in all versions).
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Widget getWidget(String id) {
        // Generated convenience method for getWidgetWithResponse
        RequestOptions requestOptions = new RequestOptions();
        return getWidgetWithResponse(id, requestOptions).getValue().toObject(Widget.class);
    }

    /**
     * Update widget color (preview only).
     * 
     * @param id The id parameter.
     * @param colorUpdate The colorUpdate parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a simple model for testing.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Widget updateWidgetColor(String id, UpdateWidgetColorRequest colorUpdate) {
        // Generated convenience method for updateWidgetColorWithResponse
        RequestOptions requestOptions = new RequestOptions();
        JsonMergePatchHelper.getUpdateWidgetColorRequestAccessor().prepareModelForJsonMergePatch(colorUpdate, true);
        BinaryData colorUpdateInBinaryData = BinaryData.fromObject(colorUpdate);
        // BinaryData.fromObject() will not fire serialization, use getLength() to fire serialization.
        colorUpdateInBinaryData.getLength();
        JsonMergePatchHelper.getUpdateWidgetColorRequestAccessor().prepareModelForJsonMergePatch(colorUpdate, false);
        return updateWidgetColorWithResponse(id, colorUpdateInBinaryData, requestOptions).getValue()
            .toObject(Widget.class);
    }

    /**
     * List widgets with optional color filtering.
     * 
     * @param name The name parameter.
     * @param color The color parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ListWidgetsResponse listWidgets(String name, String color) {
        // Generated convenience method for listWidgetsWithResponse
        RequestOptions requestOptions = new RequestOptions();
        if (name != null) {
            requestOptions.addQueryParam("name", name, false);
        }
        if (color != null) {
            requestOptions.addQueryParam("color", color, false);
        }
        return listWidgetsWithResponse(requestOptions).getValue().toObject(ListWidgetsResponse.class);
    }

    /**
     * List widgets with optional color filtering.
     * 
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ListWidgetsResponse listWidgets() {
        // Generated convenience method for listWidgetsWithResponse
        RequestOptions requestOptions = new RequestOptions();
        return listWidgetsWithResponse(requestOptions).getValue().toObject(ListWidgetsResponse.class);
    }
}
