// 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"
	"github.com/go-openapi/validate"
)

// RoleXOResponse role x o response
//
// swagger:model RoleXOResponse
type RoleXOResponse struct {

	// The description of this role.
	Description string `json:"description,omitempty"`

	// The id of the role.
	ID string `json:"id,omitempty"`

	// The name of the role.
	Name string `json:"name,omitempty"`

	// The list of privileges assigned to this role.
	// Unique: true
	Privileges []string `json:"privileges"`

	// Indicates whether the role can be changed. The system will ignore any supplied external values.
	ReadOnly bool `json:"readOnly,omitempty"`

	// The list of roles assigned to this role.
	// Unique: true
	Roles []string `json:"roles"`

	// The user source which is the origin of this role.
	Source string `json:"source,omitempty"`
}

// Validate validates this role x o response
func (m *RoleXOResponse) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *RoleXOResponse) validatePrivileges(formats strfmt.Registry) error {
	if swag.IsZero(m.Privileges) { // not required
		return nil
	}

	if err := validate.UniqueItems("privileges", "body", m.Privileges); err != nil {
		return err
	}

	return nil
}

func (m *RoleXOResponse) validateRoles(formats strfmt.Registry) error {
	if swag.IsZero(m.Roles) { // not required
		return nil
	}

	if err := validate.UniqueItems("roles", "body", m.Roles); err != nil {
		return err
	}

	return nil
}

// ContextValidate validates this role x o response based on context it is used
func (m *RoleXOResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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