/*
Configuration API

API version: 2
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package balanceplatform

import (
	"context"
	"encoding/json"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"

	"github.com/adyen/adyen-go-api-library/v21/src/common"
)

// PaymentInstrumentGroupsApi service
type PaymentInstrumentGroupsApi common.Service

// All parameters accepted by PaymentInstrumentGroupsApi.CreatePaymentInstrumentGroup
type PaymentInstrumentGroupsApiCreatePaymentInstrumentGroupInput struct {
	paymentInstrumentGroupInfo *PaymentInstrumentGroupInfo
}

func (r PaymentInstrumentGroupsApiCreatePaymentInstrumentGroupInput) PaymentInstrumentGroupInfo(paymentInstrumentGroupInfo PaymentInstrumentGroupInfo) PaymentInstrumentGroupsApiCreatePaymentInstrumentGroupInput {
	r.paymentInstrumentGroupInfo = &paymentInstrumentGroupInfo
	return r
}

/*
Prepare a request for CreatePaymentInstrumentGroup

@return PaymentInstrumentGroupsApiCreatePaymentInstrumentGroupInput
*/
func (a *PaymentInstrumentGroupsApi) CreatePaymentInstrumentGroupInput() PaymentInstrumentGroupsApiCreatePaymentInstrumentGroupInput {
	return PaymentInstrumentGroupsApiCreatePaymentInstrumentGroupInput{}
}

/*
CreatePaymentInstrumentGroup Create a payment instrument group

Creates a payment instrument group to associate and group payment instrument resources together. You can apply a transaction rule to a payment instrument group.

@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param r PaymentInstrumentGroupsApiCreatePaymentInstrumentGroupInput - Request parameters, see CreatePaymentInstrumentGroupInput
@return PaymentInstrumentGroup, *http.Response, error
*/
func (a *PaymentInstrumentGroupsApi) CreatePaymentInstrumentGroup(ctx context.Context, r PaymentInstrumentGroupsApiCreatePaymentInstrumentGroupInput) (PaymentInstrumentGroup, *http.Response, error) {
	res := &PaymentInstrumentGroup{}
	path := "/paymentInstrumentGroups"
	queryParams := url.Values{}
	headerParams := make(map[string]string)
	httpRes, err := common.SendAPIRequest(
		ctx,
		a.Client,
		r.paymentInstrumentGroupInfo,
		res,
		http.MethodPost,
		a.BasePath()+path,
		queryParams,
		headerParams,
	)

	if httpRes == nil {
		return *res, httpRes, err
	}

	var serviceError common.RestServiceError
	if httpRes.StatusCode == 400 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 401 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 403 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 422 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 500 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}

	return *res, httpRes, err
}

// All parameters accepted by PaymentInstrumentGroupsApi.GetAllTransactionRulesForPaymentInstrumentGroup
type PaymentInstrumentGroupsApiGetAllTransactionRulesForPaymentInstrumentGroupInput struct {
	id string
}

/*
Prepare a request for GetAllTransactionRulesForPaymentInstrumentGroup
@param id The unique identifier of the payment instrument group.
@return PaymentInstrumentGroupsApiGetAllTransactionRulesForPaymentInstrumentGroupInput
*/
func (a *PaymentInstrumentGroupsApi) GetAllTransactionRulesForPaymentInstrumentGroupInput(id string) PaymentInstrumentGroupsApiGetAllTransactionRulesForPaymentInstrumentGroupInput {
	return PaymentInstrumentGroupsApiGetAllTransactionRulesForPaymentInstrumentGroupInput{
		id: id,
	}
}

/*
GetAllTransactionRulesForPaymentInstrumentGroup Get all transaction rules for a payment instrument group

Returns a list of all the transaction rules associated with a payment instrument group.

@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param r PaymentInstrumentGroupsApiGetAllTransactionRulesForPaymentInstrumentGroupInput - Request parameters, see GetAllTransactionRulesForPaymentInstrumentGroupInput
@return TransactionRulesResponse, *http.Response, error
*/
func (a *PaymentInstrumentGroupsApi) GetAllTransactionRulesForPaymentInstrumentGroup(ctx context.Context, r PaymentInstrumentGroupsApiGetAllTransactionRulesForPaymentInstrumentGroupInput) (TransactionRulesResponse, *http.Response, error) {
	res := &TransactionRulesResponse{}
	path := "/paymentInstrumentGroups/{id}/transactionRules"
	path = strings.Replace(path, "{"+"id"+"}", url.PathEscape(common.ParameterValueToString(r.id, "id")), -1)
	queryParams := url.Values{}
	headerParams := make(map[string]string)
	httpRes, err := common.SendAPIRequest(
		ctx,
		a.Client,
		nil,
		res,
		http.MethodGet,
		a.BasePath()+path,
		queryParams,
		headerParams,
	)

	if httpRes == nil {
		return *res, httpRes, err
	}

	var serviceError common.RestServiceError
	if httpRes.StatusCode == 400 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 401 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 403 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 422 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 500 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}

	return *res, httpRes, err
}

// All parameters accepted by PaymentInstrumentGroupsApi.GetPaymentInstrumentGroup
type PaymentInstrumentGroupsApiGetPaymentInstrumentGroupInput struct {
	id string
}

/*
Prepare a request for GetPaymentInstrumentGroup
@param id The unique identifier of the payment instrument group.
@return PaymentInstrumentGroupsApiGetPaymentInstrumentGroupInput
*/
func (a *PaymentInstrumentGroupsApi) GetPaymentInstrumentGroupInput(id string) PaymentInstrumentGroupsApiGetPaymentInstrumentGroupInput {
	return PaymentInstrumentGroupsApiGetPaymentInstrumentGroupInput{
		id: id,
	}
}

/*
GetPaymentInstrumentGroup Get a payment instrument group

Returns the details of a payment instrument group.

@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param r PaymentInstrumentGroupsApiGetPaymentInstrumentGroupInput - Request parameters, see GetPaymentInstrumentGroupInput
@return PaymentInstrumentGroup, *http.Response, error
*/
func (a *PaymentInstrumentGroupsApi) GetPaymentInstrumentGroup(ctx context.Context, r PaymentInstrumentGroupsApiGetPaymentInstrumentGroupInput) (PaymentInstrumentGroup, *http.Response, error) {
	res := &PaymentInstrumentGroup{}
	path := "/paymentInstrumentGroups/{id}"
	path = strings.Replace(path, "{"+"id"+"}", url.PathEscape(common.ParameterValueToString(r.id, "id")), -1)
	queryParams := url.Values{}
	headerParams := make(map[string]string)
	httpRes, err := common.SendAPIRequest(
		ctx,
		a.Client,
		nil,
		res,
		http.MethodGet,
		a.BasePath()+path,
		queryParams,
		headerParams,
	)

	if httpRes == nil {
		return *res, httpRes, err
	}

	var serviceError common.RestServiceError
	if httpRes.StatusCode == 400 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 401 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 403 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 422 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}
	if httpRes.StatusCode == 500 {
		body, _ := ioutil.ReadAll(httpRes.Body)
		decodeError := json.Unmarshal([]byte(body), &serviceError)
		if decodeError != nil {
			return *res, httpRes, decodeError
		}
		return *res, httpRes, serviceError
	}

	return *res, httpRes, err
}
