// Code generated by go-swagger; DO NOT EDIT.

package models

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

import (
	"context"
	"strconv"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// SearchOrgServiceAccountsResult swagger: model
//
// swagger:model SearchOrgServiceAccountsResult
type SearchOrgServiceAccountsResult struct {

	// page
	Page int64 `json:"page,omitempty"`

	// per page
	PerPage int64 `json:"perPage,omitempty"`

	// service accounts
	ServiceAccounts []*ServiceAccountDTO `json:"serviceAccounts"`

	// It can be used for pagination of the user list
	// E.g. if totalCount is equal to 100 users and
	// the perpage parameter is set to 10 then there are 10 pages of users.
	TotalCount int64 `json:"totalCount,omitempty"`
}

// Validate validates this search org service accounts result
func (m *SearchOrgServiceAccountsResult) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateServiceAccounts(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *SearchOrgServiceAccountsResult) validateServiceAccounts(formats strfmt.Registry) error {
	if swag.IsZero(m.ServiceAccounts) { // not required
		return nil
	}

	for i := 0; i < len(m.ServiceAccounts); i++ {
		if swag.IsZero(m.ServiceAccounts[i]) { // not required
			continue
		}

		if m.ServiceAccounts[i] != nil {
			if err := m.ServiceAccounts[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("serviceAccounts" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("serviceAccounts" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this search org service accounts result based on the context it is used
func (m *SearchOrgServiceAccountsResult) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := m.contextValidateServiceAccounts(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *SearchOrgServiceAccountsResult) contextValidateServiceAccounts(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.ServiceAccounts); i++ {

		if m.ServiceAccounts[i] != nil {

			if swag.IsZero(m.ServiceAccounts[i]) { // not required
				return nil
			}

			if err := m.ServiceAccounts[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("serviceAccounts" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("serviceAccounts" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// MarshalBinary interface implementation
func (m *SearchOrgServiceAccountsResult) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *SearchOrgServiceAccountsResult) UnmarshalBinary(b []byte) error {
	var res SearchOrgServiceAccountsResult
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
