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

package ops

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

// EntityIncidentPostMortem entity incident post mortem
//
// swagger:model entity.IncidentPostMortem
type EntityIncidentPostMortem struct {

	// action items
	ActionItems []*EntityIncidentPostMortemToDoAction `json:"action_items"`

	// background
	Background string `json:"background,omitempty"`

	// bug mechanism
	BugMechanism string `json:"bug_mechanism,omitempty"`

	// created at
	CreatedAt string `json:"created_at,omitempty"`

	// customer impact minutes
	CustomerImpactMinutes int64 `json:"customer_impact_minutes,omitempty"`

	// id
	ID int64 `json:"id,omitempty"`

	// impact
	Impact string `json:"impact,omitempty"`

	// incident end time
	IncidentEndTime string `json:"incident_end_time,omitempty"`

	// incident id
	IncidentID int64 `json:"incident_id,omitempty"`

	// incident start time
	IncidentStartTime string `json:"incident_start_time,omitempty"`

	// involved engineers
	InvolvedEngineers []*EntityUser `json:"involved_engineers"`

	// involved tenants
	InvolvedTenants string `json:"involved_tenants,omitempty"`

	// minutes to detect
	MinutesToDetect int64 `json:"minutes_to_detect,omitempty"`

	// minutes to resolved
	MinutesToResolved int64 `json:"minutes_to_resolved,omitempty"`

	// resolution
	Resolution string `json:"resolution,omitempty"`

	// reviewed at
	ReviewedAt string `json:"reviewed_at,omitempty"`

	// root causes
	RootCauses string `json:"root_causes,omitempty"`

	// summary
	Summary string `json:"summary,omitempty"`

	// technical impact level
	TechnicalImpactLevel string `json:"technical_impact_level,omitempty"`

	// timeline
	Timeline []*EntityIncidentPostMortemTimelineItem `json:"timeline"`

	// top issues
	TopIssues string `json:"top_issues,omitempty"`

	// what did not work
	WhatDidNotWork string `json:"what_did_not_work,omitempty"`

	// what worked
	WhatWorked string `json:"what_worked,omitempty"`

	// where we were lucky
	WhereWeWereLucky string `json:"where_we_were_lucky,omitempty"`
}

// Validate validates this entity incident post mortem
func (m *EntityIncidentPostMortem) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *EntityIncidentPostMortem) validateActionItems(formats strfmt.Registry) error {
	if swag.IsZero(m.ActionItems) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *EntityIncidentPostMortem) validateInvolvedEngineers(formats strfmt.Registry) error {
	if swag.IsZero(m.InvolvedEngineers) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *EntityIncidentPostMortem) validateTimeline(formats strfmt.Registry) error {
	if swag.IsZero(m.Timeline) { // not required
		return nil
	}

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

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

	}

	return nil
}

// ContextValidate validate this entity incident post mortem based on the context it is used
func (m *EntityIncidentPostMortem) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *EntityIncidentPostMortem) contextValidateActionItems(ctx context.Context, formats strfmt.Registry) error {

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

		if m.ActionItems[i] != nil {

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

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

	}

	return nil
}

func (m *EntityIncidentPostMortem) contextValidateInvolvedEngineers(ctx context.Context, formats strfmt.Registry) error {

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

		if m.InvolvedEngineers[i] != nil {

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

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

	}

	return nil
}

func (m *EntityIncidentPostMortem) contextValidateTimeline(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Timeline[i] != nil {

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

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

	}

	return nil
}

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

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