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

// HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment hashicorp cloud waypoint v20241122 UI action config bundle application assignment
//
// swagger:model hashicorp.cloud.waypoint.v20241122.UI.ActionConfigBundle.ApplicationAssignment
type HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment 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 *HashicorpCloudWaypointV20241122RefApplication `json:"application,omitempty"`

	// The latest action run, if one exists. Nil if none found.
	LatestRun *HashicorpCloudWaypointV20241122ActionRun `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 v20241122 UI action config bundle application assignment
func (m *HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment) 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 *HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment) 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 *HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment) 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 v20241122 UI action config bundle application assignment based on the context it is used
func (m *HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment) 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 *HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment) 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 *HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment) 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 *HashicorpCloudWaypointV20241122UIActionConfigBundleApplicationAssignment) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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