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

// HashicorpCloudWaypointUIActionConfigBundleApplicationAssignment hashicorp cloud waypoint UI action config bundle application assignment
//
// swagger:model hashicorp.cloud.waypoint.UI.ActionConfigBundle.ApplicationAssignment
type HashicorpCloudWaypointUIActionConfigBundleApplicationAssignment struct {

	// The application ref that is assigned
	// This should be using the Name over the ID, because the frontend will
	// want the name to save a lookup.
	Application *HashicorpCloudWaypointRefApplication `json:"application,omitempty"`

	// The latest action run, if one exists. Nil if none found.
	LatestRun *HashicorpCloudWaypointActionRun `json:"latest_run,omitempty"`

	// The total action runs for this app within the last day
	TotalRunsLastDay string `json:"total_runs_last_day,omitempty"`
}

// Validate validates this hashicorp cloud waypoint UI action config bundle application assignment
func (m *HashicorpCloudWaypointUIActionConfigBundleApplicationAssignment) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudWaypointUIActionConfigBundleApplicationAssignment) validateApplication(formats strfmt.Registry) error {
	if swag.IsZero(m.Application) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudWaypointUIActionConfigBundleApplicationAssignment) validateLatestRun(formats strfmt.Registry) error {
	if swag.IsZero(m.LatestRun) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this hashicorp cloud waypoint UI action config bundle application assignment based on the context it is used
func (m *HashicorpCloudWaypointUIActionConfigBundleApplicationAssignment) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudWaypointUIActionConfigBundleApplicationAssignment) contextValidateApplication(ctx context.Context, formats strfmt.Registry) error {

	if m.Application != nil {

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

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

	return nil
}

func (m *HashicorpCloudWaypointUIActionConfigBundleApplicationAssignment) contextValidateLatestRun(ctx context.Context, formats strfmt.Registry) error {

	if m.LatestRun != nil {

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

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

	return nil
}

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

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