// Code generated by msgraph-generate.go DO NOT EDIT.

package msgraph

import (
	"context"
	"fmt"
	"io/ioutil"
	"net/http"

	"github.com/yaegashi/msgraph.go/jsonx"
)

// ImportedAppleDeviceIdentityRequestBuilder is request builder for ImportedAppleDeviceIdentity
type ImportedAppleDeviceIdentityRequestBuilder struct{ BaseRequestBuilder }

// Request returns ImportedAppleDeviceIdentityRequest
func (b *ImportedAppleDeviceIdentityRequestBuilder) Request() *ImportedAppleDeviceIdentityRequest {
	return &ImportedAppleDeviceIdentityRequest{
		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
	}
}

// ImportedAppleDeviceIdentityRequest is request for ImportedAppleDeviceIdentity
type ImportedAppleDeviceIdentityRequest struct{ BaseRequest }

// Get performs GET request for ImportedAppleDeviceIdentity
func (r *ImportedAppleDeviceIdentityRequest) Get(ctx context.Context) (resObj *ImportedAppleDeviceIdentity, err error) {
	var query string
	if r.query != nil {
		query = "?" + r.query.Encode()
	}
	err = r.JSONRequest(ctx, "GET", query, nil, &resObj)
	return
}

// Update performs PATCH request for ImportedAppleDeviceIdentity
func (r *ImportedAppleDeviceIdentityRequest) Update(ctx context.Context, reqObj *ImportedAppleDeviceIdentity) error {
	return r.JSONRequest(ctx, "PATCH", "", reqObj, nil)
}

// Delete performs DELETE request for ImportedAppleDeviceIdentity
func (r *ImportedAppleDeviceIdentityRequest) Delete(ctx context.Context) error {
	return r.JSONRequest(ctx, "DELETE", "", nil, nil)
}

// ImportedDeviceIdentityRequestBuilder is request builder for ImportedDeviceIdentity
type ImportedDeviceIdentityRequestBuilder struct{ BaseRequestBuilder }

// Request returns ImportedDeviceIdentityRequest
func (b *ImportedDeviceIdentityRequestBuilder) Request() *ImportedDeviceIdentityRequest {
	return &ImportedDeviceIdentityRequest{
		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
	}
}

// ImportedDeviceIdentityRequest is request for ImportedDeviceIdentity
type ImportedDeviceIdentityRequest struct{ BaseRequest }

// Get performs GET request for ImportedDeviceIdentity
func (r *ImportedDeviceIdentityRequest) Get(ctx context.Context) (resObj *ImportedDeviceIdentity, err error) {
	var query string
	if r.query != nil {
		query = "?" + r.query.Encode()
	}
	err = r.JSONRequest(ctx, "GET", query, nil, &resObj)
	return
}

// Update performs PATCH request for ImportedDeviceIdentity
func (r *ImportedDeviceIdentityRequest) Update(ctx context.Context, reqObj *ImportedDeviceIdentity) error {
	return r.JSONRequest(ctx, "PATCH", "", reqObj, nil)
}

// Delete performs DELETE request for ImportedDeviceIdentity
func (r *ImportedDeviceIdentityRequest) Delete(ctx context.Context) error {
	return r.JSONRequest(ctx, "DELETE", "", nil, nil)
}

// ImportedWindowsAutopilotDeviceIdentityRequestBuilder is request builder for ImportedWindowsAutopilotDeviceIdentity
type ImportedWindowsAutopilotDeviceIdentityRequestBuilder struct{ BaseRequestBuilder }

// Request returns ImportedWindowsAutopilotDeviceIdentityRequest
func (b *ImportedWindowsAutopilotDeviceIdentityRequestBuilder) Request() *ImportedWindowsAutopilotDeviceIdentityRequest {
	return &ImportedWindowsAutopilotDeviceIdentityRequest{
		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
	}
}

// ImportedWindowsAutopilotDeviceIdentityRequest is request for ImportedWindowsAutopilotDeviceIdentity
type ImportedWindowsAutopilotDeviceIdentityRequest struct{ BaseRequest }

// Get performs GET request for ImportedWindowsAutopilotDeviceIdentity
func (r *ImportedWindowsAutopilotDeviceIdentityRequest) Get(ctx context.Context) (resObj *ImportedWindowsAutopilotDeviceIdentity, err error) {
	var query string
	if r.query != nil {
		query = "?" + r.query.Encode()
	}
	err = r.JSONRequest(ctx, "GET", query, nil, &resObj)
	return
}

// Update performs PATCH request for ImportedWindowsAutopilotDeviceIdentity
func (r *ImportedWindowsAutopilotDeviceIdentityRequest) Update(ctx context.Context, reqObj *ImportedWindowsAutopilotDeviceIdentity) error {
	return r.JSONRequest(ctx, "PATCH", "", reqObj, nil)
}

// Delete performs DELETE request for ImportedWindowsAutopilotDeviceIdentity
func (r *ImportedWindowsAutopilotDeviceIdentityRequest) Delete(ctx context.Context) error {
	return r.JSONRequest(ctx, "DELETE", "", nil, nil)
}

// ImportedWindowsAutopilotDeviceIdentityUploadRequestBuilder is request builder for ImportedWindowsAutopilotDeviceIdentityUpload
type ImportedWindowsAutopilotDeviceIdentityUploadRequestBuilder struct{ BaseRequestBuilder }

// Request returns ImportedWindowsAutopilotDeviceIdentityUploadRequest
func (b *ImportedWindowsAutopilotDeviceIdentityUploadRequestBuilder) Request() *ImportedWindowsAutopilotDeviceIdentityUploadRequest {
	return &ImportedWindowsAutopilotDeviceIdentityUploadRequest{
		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
	}
}

// ImportedWindowsAutopilotDeviceIdentityUploadRequest is request for ImportedWindowsAutopilotDeviceIdentityUpload
type ImportedWindowsAutopilotDeviceIdentityUploadRequest struct{ BaseRequest }

// Get performs GET request for ImportedWindowsAutopilotDeviceIdentityUpload
func (r *ImportedWindowsAutopilotDeviceIdentityUploadRequest) Get(ctx context.Context) (resObj *ImportedWindowsAutopilotDeviceIdentityUpload, err error) {
	var query string
	if r.query != nil {
		query = "?" + r.query.Encode()
	}
	err = r.JSONRequest(ctx, "GET", query, nil, &resObj)
	return
}

// Update performs PATCH request for ImportedWindowsAutopilotDeviceIdentityUpload
func (r *ImportedWindowsAutopilotDeviceIdentityUploadRequest) Update(ctx context.Context, reqObj *ImportedWindowsAutopilotDeviceIdentityUpload) error {
	return r.JSONRequest(ctx, "PATCH", "", reqObj, nil)
}

// Delete performs DELETE request for ImportedWindowsAutopilotDeviceIdentityUpload
func (r *ImportedWindowsAutopilotDeviceIdentityUploadRequest) Delete(ctx context.Context) error {
	return r.JSONRequest(ctx, "DELETE", "", nil, nil)
}

//
type ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequestBuilder struct{ BaseRequestBuilder }

// ImportAppleDeviceIdentityList action undocumented
func (b *DepOnboardingSettingImportedAppleDeviceIdentitiesCollectionRequestBuilder) ImportAppleDeviceIdentityList(reqObj *ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequestParameter) *ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequestBuilder {
	bb := &ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
	bb.BaseRequestBuilder.baseURL += "/importAppleDeviceIdentityList"
	bb.BaseRequestBuilder.requestObject = reqObj
	return bb
}

//
type ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequest struct{ BaseRequest }

//
func (b *ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequestBuilder) Request() *ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequest {
	return &ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequest{
		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client, requestObject: b.requestObject},
	}
}

//
func (r *ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]ImportedAppleDeviceIdentityResult, error) {
	req, err := r.NewJSONRequest(method, path, obj)
	if err != nil {
		return nil, err
	}
	if ctx != nil {
		req = req.WithContext(ctx)
	}
	res, err := r.client.Do(req)
	if err != nil {
		return nil, err
	}
	var values []ImportedAppleDeviceIdentityResult
	for {
		defer res.Body.Close()
		if res.StatusCode != http.StatusOK {
			b, _ := ioutil.ReadAll(res.Body)
			errRes := &ErrorResponse{Response: res}
			err := jsonx.Unmarshal(b, errRes)
			if err != nil {
				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
			}
			return nil, errRes
		}
		var (
			paging Paging
			value  []ImportedAppleDeviceIdentityResult
		)
		err := jsonx.NewDecoder(res.Body).Decode(&paging)
		if err != nil {
			return nil, err
		}
		err = jsonx.Unmarshal(paging.Value, &value)
		if err != nil {
			return nil, err
		}
		values = append(values, value...)
		if n >= 0 {
			n--
		}
		if n == 0 || len(paging.NextLink) == 0 {
			return values, nil
		}
		req, err = http.NewRequest("GET", paging.NextLink, nil)
		if ctx != nil {
			req = req.WithContext(ctx)
		}
		res, err = r.client.Do(req)
		if err != nil {
			return nil, err
		}
	}
}

//
func (r *ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequest) PostN(ctx context.Context, n int) ([]ImportedAppleDeviceIdentityResult, error) {
	return r.Paging(ctx, "POST", "", r.requestObject, n)
}

//
func (r *ImportedAppleDeviceIdentityCollectionImportAppleDeviceIdentityListRequest) Post(ctx context.Context) ([]ImportedAppleDeviceIdentityResult, error) {
	return r.Paging(ctx, "POST", "", r.requestObject, 0)
}

//
type ImportedDeviceIdentityCollectionImportDeviceIdentityListRequestBuilder struct{ BaseRequestBuilder }

// ImportDeviceIdentityList action undocumented
func (b *DeviceManagementImportedDeviceIdentitiesCollectionRequestBuilder) ImportDeviceIdentityList(reqObj *ImportedDeviceIdentityCollectionImportDeviceIdentityListRequestParameter) *ImportedDeviceIdentityCollectionImportDeviceIdentityListRequestBuilder {
	bb := &ImportedDeviceIdentityCollectionImportDeviceIdentityListRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
	bb.BaseRequestBuilder.baseURL += "/importDeviceIdentityList"
	bb.BaseRequestBuilder.requestObject = reqObj
	return bb
}

//
type ImportedDeviceIdentityCollectionImportDeviceIdentityListRequest struct{ BaseRequest }

//
func (b *ImportedDeviceIdentityCollectionImportDeviceIdentityListRequestBuilder) Request() *ImportedDeviceIdentityCollectionImportDeviceIdentityListRequest {
	return &ImportedDeviceIdentityCollectionImportDeviceIdentityListRequest{
		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client, requestObject: b.requestObject},
	}
}

//
func (r *ImportedDeviceIdentityCollectionImportDeviceIdentityListRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]ImportedDeviceIdentityResult, error) {
	req, err := r.NewJSONRequest(method, path, obj)
	if err != nil {
		return nil, err
	}
	if ctx != nil {
		req = req.WithContext(ctx)
	}
	res, err := r.client.Do(req)
	if err != nil {
		return nil, err
	}
	var values []ImportedDeviceIdentityResult
	for {
		defer res.Body.Close()
		if res.StatusCode != http.StatusOK {
			b, _ := ioutil.ReadAll(res.Body)
			errRes := &ErrorResponse{Response: res}
			err := jsonx.Unmarshal(b, errRes)
			if err != nil {
				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
			}
			return nil, errRes
		}
		var (
			paging Paging
			value  []ImportedDeviceIdentityResult
		)
		err := jsonx.NewDecoder(res.Body).Decode(&paging)
		if err != nil {
			return nil, err
		}
		err = jsonx.Unmarshal(paging.Value, &value)
		if err != nil {
			return nil, err
		}
		values = append(values, value...)
		if n >= 0 {
			n--
		}
		if n == 0 || len(paging.NextLink) == 0 {
			return values, nil
		}
		req, err = http.NewRequest("GET", paging.NextLink, nil)
		if ctx != nil {
			req = req.WithContext(ctx)
		}
		res, err = r.client.Do(req)
		if err != nil {
			return nil, err
		}
	}
}

//
func (r *ImportedDeviceIdentityCollectionImportDeviceIdentityListRequest) PostN(ctx context.Context, n int) ([]ImportedDeviceIdentityResult, error) {
	return r.Paging(ctx, "POST", "", r.requestObject, n)
}

//
func (r *ImportedDeviceIdentityCollectionImportDeviceIdentityListRequest) Post(ctx context.Context) ([]ImportedDeviceIdentityResult, error) {
	return r.Paging(ctx, "POST", "", r.requestObject, 0)
}

//
type ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequestBuilder struct{ BaseRequestBuilder }

// SearchExistingIdentities action undocumented
func (b *DeviceManagementImportedDeviceIdentitiesCollectionRequestBuilder) SearchExistingIdentities(reqObj *ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequestParameter) *ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequestBuilder {
	bb := &ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
	bb.BaseRequestBuilder.baseURL += "/searchExistingIdentities"
	bb.BaseRequestBuilder.requestObject = reqObj
	return bb
}

//
type ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequest struct{ BaseRequest }

//
func (b *ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequestBuilder) Request() *ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequest {
	return &ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequest{
		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client, requestObject: b.requestObject},
	}
}

//
func (r *ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]ImportedDeviceIdentity, error) {
	req, err := r.NewJSONRequest(method, path, obj)
	if err != nil {
		return nil, err
	}
	if ctx != nil {
		req = req.WithContext(ctx)
	}
	res, err := r.client.Do(req)
	if err != nil {
		return nil, err
	}
	var values []ImportedDeviceIdentity
	for {
		defer res.Body.Close()
		if res.StatusCode != http.StatusOK {
			b, _ := ioutil.ReadAll(res.Body)
			errRes := &ErrorResponse{Response: res}
			err := jsonx.Unmarshal(b, errRes)
			if err != nil {
				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
			}
			return nil, errRes
		}
		var (
			paging Paging
			value  []ImportedDeviceIdentity
		)
		err := jsonx.NewDecoder(res.Body).Decode(&paging)
		if err != nil {
			return nil, err
		}
		err = jsonx.Unmarshal(paging.Value, &value)
		if err != nil {
			return nil, err
		}
		values = append(values, value...)
		if n >= 0 {
			n--
		}
		if n == 0 || len(paging.NextLink) == 0 {
			return values, nil
		}
		req, err = http.NewRequest("GET", paging.NextLink, nil)
		if ctx != nil {
			req = req.WithContext(ctx)
		}
		res, err = r.client.Do(req)
		if err != nil {
			return nil, err
		}
	}
}

//
func (r *ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequest) PostN(ctx context.Context, n int) ([]ImportedDeviceIdentity, error) {
	return r.Paging(ctx, "POST", "", r.requestObject, n)
}

//
func (r *ImportedDeviceIdentityCollectionSearchExistingIdentitiesRequest) Post(ctx context.Context) ([]ImportedDeviceIdentity, error) {
	return r.Paging(ctx, "POST", "", r.requestObject, 0)
}

//
type ImportedWindowsAutopilotDeviceIdentityCollectionImportRequestBuilder struct{ BaseRequestBuilder }

// Import action undocumented
func (b *DeviceManagementImportedWindowsAutopilotDeviceIdentitiesCollectionRequestBuilder) Import(reqObj *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequestParameter) *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequestBuilder {
	bb := &ImportedWindowsAutopilotDeviceIdentityCollectionImportRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
	bb.BaseRequestBuilder.baseURL += "/import"
	bb.BaseRequestBuilder.requestObject = reqObj
	return bb
}

// Import action undocumented
func (b *ImportedWindowsAutopilotDeviceIdentityUploadDeviceIdentitiesCollectionRequestBuilder) Import(reqObj *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequestParameter) *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequestBuilder {
	bb := &ImportedWindowsAutopilotDeviceIdentityCollectionImportRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
	bb.BaseRequestBuilder.baseURL += "/import"
	bb.BaseRequestBuilder.requestObject = reqObj
	return bb
}

//
type ImportedWindowsAutopilotDeviceIdentityCollectionImportRequest struct{ BaseRequest }

//
func (b *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequestBuilder) Request() *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequest {
	return &ImportedWindowsAutopilotDeviceIdentityCollectionImportRequest{
		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client, requestObject: b.requestObject},
	}
}

//
func (r *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]ImportedWindowsAutopilotDeviceIdentity, error) {
	req, err := r.NewJSONRequest(method, path, obj)
	if err != nil {
		return nil, err
	}
	if ctx != nil {
		req = req.WithContext(ctx)
	}
	res, err := r.client.Do(req)
	if err != nil {
		return nil, err
	}
	var values []ImportedWindowsAutopilotDeviceIdentity
	for {
		defer res.Body.Close()
		if res.StatusCode != http.StatusOK {
			b, _ := ioutil.ReadAll(res.Body)
			errRes := &ErrorResponse{Response: res}
			err := jsonx.Unmarshal(b, errRes)
			if err != nil {
				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
			}
			return nil, errRes
		}
		var (
			paging Paging
			value  []ImportedWindowsAutopilotDeviceIdentity
		)
		err := jsonx.NewDecoder(res.Body).Decode(&paging)
		if err != nil {
			return nil, err
		}
		err = jsonx.Unmarshal(paging.Value, &value)
		if err != nil {
			return nil, err
		}
		values = append(values, value...)
		if n >= 0 {
			n--
		}
		if n == 0 || len(paging.NextLink) == 0 {
			return values, nil
		}
		req, err = http.NewRequest("GET", paging.NextLink, nil)
		if ctx != nil {
			req = req.WithContext(ctx)
		}
		res, err = r.client.Do(req)
		if err != nil {
			return nil, err
		}
	}
}

//
func (r *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequest) PostN(ctx context.Context, n int) ([]ImportedWindowsAutopilotDeviceIdentity, error) {
	return r.Paging(ctx, "POST", "", r.requestObject, n)
}

//
func (r *ImportedWindowsAutopilotDeviceIdentityCollectionImportRequest) Post(ctx context.Context) ([]ImportedWindowsAutopilotDeviceIdentity, error) {
	return r.Paging(ctx, "POST", "", r.requestObject, 0)
}
