// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.quantum.jobs;

import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.rest.PagedIterable;
import com.azure.quantum.jobs.implementation.JobsImpl;
import com.azure.quantum.jobs.models.JobDetails;
import com.azure.quantum.jobs.models.RestErrorException;

/** Initializes a new instance of the synchronous QuantumClient type. */
@ServiceClient(builder = QuantumClientBuilder.class)
public final class JobsClient {
    private final JobsImpl serviceClient;

    /**
     * Initializes an instance of Jobs client.
     *
     * @param serviceClient the service client implementation.
     */
    JobsClient(JobsImpl serviceClient) {
        this.serviceClient = serviceClient;
    }

    /**
     * List jobs.
     *
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of job details.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<JobDetails> list() {
        return this.serviceClient.list();
    }

    /**
     * Get job by id.
     *
     * @param jobId Id of the job.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws RestErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return job by id.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public JobDetails get(String jobId) {
        return this.serviceClient.get(jobId);
    }

    /**
     * Create a job.
     *
     * @param jobId Id of the job.
     * @param job The complete metadata of the job to submit.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws RestErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return job details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public JobDetails create(String jobId, JobDetails job) {
        return this.serviceClient.create(jobId, job);
    }

    /**
     * Cancel a job.
     *
     * @param jobId Id of the job.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws RestErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void cancel(String jobId) {
        this.serviceClient.cancel(jobId);
    }
}
