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

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

// Team Team represents a team in an organization
//
// swagger:model Team
type Team struct {

	// can create org repo
	CanCreateOrgRepo bool `json:"can_create_org_repo,omitempty"`

	// description
	Description string `json:"description,omitempty"`

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

	// includes all repositories
	IncludesAllRepositories bool `json:"includes_all_repositories,omitempty"`

	// name
	Name string `json:"name,omitempty"`

	// permission
	// Enum: ["none","read","write","admin","owner"]
	Permission string `json:"permission,omitempty"`

	// units
	// Example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.projects","repo.ext_wiki"]
	Units []string `json:"units"`

	// units map
	// Example: {"repo.code":"read","repo.ext_issues":"none","repo.ext_wiki":"none","repo.issues":"write","repo.projects":"none","repo.pulls":"owner","repo.releases":"none","repo.wiki":"admin"}
	UnitsMap map[string]string `json:"units_map,omitempty"`

	// organization
	Organization *Organization `json:"organization,omitempty"`
}

// Validate validates this team
func (m *Team) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

var teamTypePermissionPropEnum []interface{}

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["none","read","write","admin","owner"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		teamTypePermissionPropEnum = append(teamTypePermissionPropEnum, v)
	}
}

const (

	// TeamPermissionNone captures enum value "none"
	TeamPermissionNone string = "none"

	// TeamPermissionRead captures enum value "read"
	TeamPermissionRead string = "read"

	// TeamPermissionWrite captures enum value "write"
	TeamPermissionWrite string = "write"

	// TeamPermissionAdmin captures enum value "admin"
	TeamPermissionAdmin string = "admin"

	// TeamPermissionOwner captures enum value "owner"
	TeamPermissionOwner string = "owner"
)

// prop value enum
func (m *Team) validatePermissionEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, teamTypePermissionPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (m *Team) validatePermission(formats strfmt.Registry) error {
	if swag.IsZero(m.Permission) { // not required
		return nil
	}

	// value enum
	if err := m.validatePermissionEnum("permission", "body", m.Permission); err != nil {
		return err
	}

	return nil
}

func (m *Team) validateOrganization(formats strfmt.Registry) error {
	if swag.IsZero(m.Organization) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *Team) contextValidateOrganization(ctx context.Context, formats strfmt.Registry) error {

	if m.Organization != nil {

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

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

	return nil
}

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

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