// 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"

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

// SecretServiceUpdateGcpDynamicSecretBody secret service update gcp dynamic secret body
//
// swagger:model SecretServiceUpdateGcpDynamicSecretBody
type SecretServiceUpdateGcpDynamicSecretBody struct {

	// default ttl
	DefaultTTL string `json:"default_ttl,omitempty"`

	// service account impersonation
	ServiceAccountImpersonation *Secrets20231128ServiceAccountImpersonationRequest `json:"service_account_impersonation,omitempty"`
}

// Validate validates this secret service update gcp dynamic secret body
func (m *SecretServiceUpdateGcpDynamicSecretBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *SecretServiceUpdateGcpDynamicSecretBody) validateServiceAccountImpersonation(formats strfmt.Registry) error {
	if swag.IsZero(m.ServiceAccountImpersonation) { // not required
		return nil
	}

	if m.ServiceAccountImpersonation != nil {
		if err := m.ServiceAccountImpersonation.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("service_account_impersonation")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("service_account_impersonation")
			}
			return err
		}
	}

	return nil
}

// ContextValidate validate this secret service update gcp dynamic secret body based on the context it is used
func (m *SecretServiceUpdateGcpDynamicSecretBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *SecretServiceUpdateGcpDynamicSecretBody) contextValidateServiceAccountImpersonation(ctx context.Context, formats strfmt.Registry) error {

	if m.ServiceAccountImpersonation != nil {

		if swag.IsZero(m.ServiceAccountImpersonation) { // not required
			return nil
		}

		if err := m.ServiceAccountImpersonation.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("service_account_impersonation")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("service_account_impersonation")
			}
			return err
		}
	}

	return nil
}

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

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