package custom_rules

import (
	"fmt"

	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
)

func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
	return &Client{transport: transport, formats: formats}
}

type Client struct {
	transport runtime.ClientTransport
	formats   strfmt.Registry
}

type ClientService interface {
	CreateCustomRule(params *CreateCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*CreateCustomRuleCreated, error)

	DeleteCustomRule(params *DeleteCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*DeleteCustomRuleNoContent, error)

	GetCustomRule(params *GetCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*GetCustomRuleOK, error)

	ListCustomRules(params *ListCustomRulesParams, authInfo runtime.ClientAuthInfoWriter) (*ListCustomRulesOK, error)

	TestCustomRule(params *TestCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*TestCustomRuleOK, error)

	TestCustomRuleInput(params *TestCustomRuleInputParams, authInfo runtime.ClientAuthInfoWriter) (*TestCustomRuleInputOK, error)

	UpdateCustomRule(params *UpdateCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateCustomRuleOK, error)

	SetTransport(transport runtime.ClientTransport)
}

func (a *Client) CreateCustomRule(params *CreateCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*CreateCustomRuleCreated, error) {

	if params == nil {
		params = NewCreateCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "createCustomRule",
		Method:             "POST",
		PathPattern:        "/rules",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &CreateCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*CreateCustomRuleCreated)
	if ok {
		return success, nil
	}

	msg := fmt.Sprintf("unexpected success response for createCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

func (a *Client) DeleteCustomRule(params *DeleteCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*DeleteCustomRuleNoContent, error) {

	if params == nil {
		params = NewDeleteCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "deleteCustomRule",
		Method:             "DELETE",
		PathPattern:        "/rules/{rule_id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &DeleteCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*DeleteCustomRuleNoContent)
	if ok {
		return success, nil
	}

	msg := fmt.Sprintf("unexpected success response for deleteCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

func (a *Client) GetCustomRule(params *GetCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*GetCustomRuleOK, error) {

	if params == nil {
		params = NewGetCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "getCustomRule",
		Method:             "GET",
		PathPattern:        "/rules/{rule_id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &GetCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*GetCustomRuleOK)
	if ok {
		return success, nil
	}

	msg := fmt.Sprintf("unexpected success response for getCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

func (a *Client) ListCustomRules(params *ListCustomRulesParams, authInfo runtime.ClientAuthInfoWriter) (*ListCustomRulesOK, error) {

	if params == nil {
		params = NewListCustomRulesParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "listCustomRules",
		Method:             "GET",
		PathPattern:        "/rules",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &ListCustomRulesReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*ListCustomRulesOK)
	if ok {
		return success, nil
	}

	msg := fmt.Sprintf("unexpected success response for listCustomRules: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

func (a *Client) TestCustomRule(params *TestCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*TestCustomRuleOK, error) {

	if params == nil {
		params = NewTestCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "testCustomRule",
		Method:             "POST",
		PathPattern:        "/rules/test",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &TestCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*TestCustomRuleOK)
	if ok {
		return success, nil
	}

	msg := fmt.Sprintf("unexpected success response for testCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

func (a *Client) TestCustomRuleInput(params *TestCustomRuleInputParams, authInfo runtime.ClientAuthInfoWriter) (*TestCustomRuleInputOK, error) {

	if params == nil {
		params = NewTestCustomRuleInputParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "testCustomRuleInput",
		Method:             "GET",
		PathPattern:        "/rules/test/input",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &TestCustomRuleInputReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*TestCustomRuleInputOK)
	if ok {
		return success, nil
	}

	msg := fmt.Sprintf("unexpected success response for testCustomRuleInput: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

func (a *Client) UpdateCustomRule(params *UpdateCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateCustomRuleOK, error) {

	if params == nil {
		params = NewUpdateCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "updateCustomRule",
		Method:             "PATCH",
		PathPattern:        "/rules/{rule_id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &UpdateCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*UpdateCustomRuleOK)
	if ok {
		return success, nil
	}

	msg := fmt.Sprintf("unexpected success response for updateCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

func (a *Client) SetTransport(transport runtime.ClientTransport) {
	a.transport = transport
}
// Code generated by go-swagger; DO NOT EDIT.

package custom_rules

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"fmt"

	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
)

// New creates a new custom rules API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
	return &Client{transport: transport, formats: formats}
}

/*
Client for custom rules API
*/
type Client struct {
	transport runtime.ClientTransport
	formats   strfmt.Registry
}

// ClientService is the interface for Client methods
type ClientService interface {
	CreateCustomRule(params *CreateCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*CreateCustomRuleCreated, error)

	DeleteCustomRule(params *DeleteCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*DeleteCustomRuleNoContent, error)

	GetCustomRule(params *GetCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*GetCustomRuleOK, error)

	ListCustomRules(params *ListCustomRulesParams, authInfo runtime.ClientAuthInfoWriter) (*ListCustomRulesOK, error)

	TestCustomRule(params *TestCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*TestCustomRuleOK, error)

	TestCustomRuleInput(params *TestCustomRuleInputParams, authInfo runtime.ClientAuthInfoWriter) (*TestCustomRuleInputOK, error)

	UpdateCustomRule(params *UpdateCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateCustomRuleOK, error)

	SetTransport(transport runtime.ClientTransport)
}

/*
  CreateCustomRule creates a new custom rule

  Create a new custom rule.

*/
func (a *Client) CreateCustomRule(params *CreateCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*CreateCustomRuleCreated, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewCreateCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "createCustomRule",
		Method:             "POST",
		PathPattern:        "/rules",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &CreateCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*CreateCustomRuleCreated)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for createCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
  DeleteCustomRule deletes a custom rule

  Delete a specified custom rule.

*/
func (a *Client) DeleteCustomRule(params *DeleteCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*DeleteCustomRuleNoContent, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewDeleteCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "deleteCustomRule",
		Method:             "DELETE",
		PathPattern:        "/rules/{rule_id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &DeleteCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*DeleteCustomRuleNoContent)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for deleteCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
  GetCustomRule gets details on a single custom rule

  Get details on a single custom rule.

*/
func (a *Client) GetCustomRule(params *GetCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*GetCustomRuleOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewGetCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "getCustomRule",
		Method:             "GET",
		PathPattern:        "/rules/{rule_id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &GetCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*GetCustomRuleOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for getCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
  ListCustomRules lists custom rules

  Return a list of custom rules.

*/
func (a *Client) ListCustomRules(params *ListCustomRulesParams, authInfo runtime.ClientAuthInfoWriter) (*ListCustomRulesOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewListCustomRulesParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "listCustomRules",
		Method:             "GET",
		PathPattern:        "/rules",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &ListCustomRulesReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*ListCustomRulesOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for listCustomRules: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
  TestCustomRule tests a custom rule

  Test a custom rule using state from an scan.

*/
func (a *Client) TestCustomRule(params *TestCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*TestCustomRuleOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewTestCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "testCustomRule",
		Method:             "POST",
		PathPattern:        "/rules/test",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &TestCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*TestCustomRuleOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for testCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
  TestCustomRuleInput gets the input for a custom rule test

  Get the input against which a custom rule would be tested.

*/
func (a *Client) TestCustomRuleInput(params *TestCustomRuleInputParams, authInfo runtime.ClientAuthInfoWriter) (*TestCustomRuleInputOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewTestCustomRuleInputParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "testCustomRuleInput",
		Method:             "GET",
		PathPattern:        "/rules/test/input",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &TestCustomRuleInputReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*TestCustomRuleInputOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for testCustomRuleInput: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
  UpdateCustomRule updates custom rule

  Update configuration of a custom rule.

*/
func (a *Client) UpdateCustomRule(params *UpdateCustomRuleParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateCustomRuleOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewUpdateCustomRuleParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "updateCustomRule",
		Method:             "PATCH",
		PathPattern:        "/rules/{rule_id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &UpdateCustomRuleReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	success, ok := result.(*UpdateCustomRuleOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for updateCustomRule: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
	a.transport = transport
}
