package server

import (
	vironviews "github.com/andmorefine/buddha/gen/viron/views"
	goa "goa.design/goa"
)

type VironAuthtypeResponseCollection []*VironAuthtypeResponse

type VironMenuResponseBody struct {
	Name      string                   `form:"name" json:"name" xml:"name"`
	Thumbnail *string                  `form:"thumbnail,omitempty" json:"thumbnail,omitempty" xml:"thumbnail,omitempty"`
	Tags      []string                 `form:"tags,omitempty" json:"tags,omitempty" xml:"tags,omitempty"`
	Color     *string                  `form:"color,omitempty" json:"color,omitempty" xml:"color,omitempty"`
	Theme     *string                  `form:"theme,omitempty" json:"theme,omitempty" xml:"theme,omitempty"`
	Pages     []*VironPageResponseBody `form:"pages" json:"pages" xml:"pages"`
}

type VironAuthtypeResponse struct {

	Type string `form:"type" json:"type" xml:"type"`

	Provider string `form:"provider" json:"provider" xml:"provider"`

	URL string `form:"url" json:"url" xml:"url"`

	Method string `form:"method" json:"method" xml:"method"`
}

type VironPageResponseBody struct {
	Section    string                        `form:"section" json:"section" xml:"section"`
	Group      *string                       `form:"group,omitempty" json:"group,omitempty" xml:"group,omitempty"`
	ID         string                        `form:"id" json:"id" xml:"id"`
	Name       string                        `form:"name" json:"name" xml:"name"`
	Components []*VironComponentResponseBody `form:"components" json:"components" xml:"components"`
}

type VironComponentResponseBody struct {
	Name           string                    `form:"name" json:"name" xml:"name"`
	Style          string                    `form:"style" json:"style" xml:"style"`
	Unit           *string                   `form:"unit,omitempty" json:"unit,omitempty" xml:"unit,omitempty"`
	Actions        []string                  `form:"actions,omitempty" json:"actions,omitempty" xml:"actions,omitempty"`
	API            *VironAPIResponseBody     `form:"api" json:"api" xml:"api"`
	Pagination     *bool                     `form:"pagination,omitempty" json:"pagination,omitempty" xml:"pagination,omitempty"`
	Primary        *string                   `form:"primary,omitempty" json:"primary,omitempty" xml:"primary,omitempty"`
	TableLabels    []string                  `form:"table_labels,omitempty" json:"table_labels,omitempty" xml:"table_labels,omitempty"`
	Query          []*VironQueryResponseBody `form:"query,omitempty" json:"query,omitempty" xml:"query,omitempty"`
	AutoRefreshSec *int32                    `form:"auto_refresh_sec,omitempty" json:"auto_refresh_sec,omitempty" xml:"auto_refresh_sec,omitempty"`
}

type VironAPIResponseBody struct {
	Method string `form:"method" json:"method" xml:"method"`
	Path   string `form:"path" json:"path" xml:"path"`
}

type VironQueryResponseBody struct {
	Key  string `form:"key" json:"key" xml:"key"`
	Type string `form:"type" json:"type" xml:"type"`
}

func NewVironAuthtypeResponseCollection(res vironviews.VironAuthtypeCollectionView) VironAuthtypeResponseCollection {
	body := make([]*VironAuthtypeResponse, len(res))
	for i, val := range res {
		body[i] = &VironAuthtypeResponse{
			Type:     *val.Type,
			Provider: *val.Provider,
			URL:      *val.URL,
			Method:   *val.Method,
		}
	}
	return body
}

func NewVironMenuResponseBody(res *vironviews.VironMenuView) *VironMenuResponseBody {
	body := &VironMenuResponseBody{
		Name:      *res.Name,
		Thumbnail: res.Thumbnail,
		Color:     res.Color,
		Theme:     res.Theme,
	}
	if res.Tags != nil {
		body.Tags = make([]string, len(res.Tags))
		for i, val := range res.Tags {
			body.Tags[i] = val
		}
	}
	if res.Pages != nil {
		body.Pages = make([]*VironPageResponseBody, len(res.Pages))
		for i, val := range res.Pages {
			body.Pages[i] = &VironPageResponseBody{
				ID:      *val.ID,
				Name:    *val.Name,
				Section: *val.Section,
				Group:   val.Group,
			}
			if val.Components != nil {
				body.Pages[i].Components = make([]*VironComponentResponseBody, len(val.Components))
				for j, val := range val.Components {
					body.Pages[i].Components[j] = &VironComponentResponseBody{
						Name:           *val.Name,
						Style:          *val.Style,
						Unit:           val.Unit,
						Pagination:     val.Pagination,
						Primary:        val.Primary,
						AutoRefreshSec: val.AutoRefreshSec,
					}
					if val.Actions != nil {
						body.Pages[i].Components[j].Actions = make([]string, len(val.Actions))
						for k, val := range val.Actions {
							body.Pages[i].Components[j].Actions[k] = val
						}
					}
					if val.API != nil {
						body.Pages[i].Components[j].API = marshalVironAPIViewToVironAPIResponseBody(val.API)
					}
					if val.TableLabels != nil {
						body.Pages[i].Components[j].TableLabels = make([]string, len(val.TableLabels))
						for k, val := range val.TableLabels {
							body.Pages[i].Components[j].TableLabels[k] = val
						}
					}
					if val.Query != nil {
						body.Pages[i].Components[j].Query = make([]*VironQueryResponseBody, len(val.Query))
						for k, val := range val.Query {
							body.Pages[i].Components[j].Query[k] = &VironQueryResponseBody{
								Key:  *val.Key,
								Type: *val.Type,
							}
						}
					}
				}
			}
		}
	}
	return body
}

func ValidateVironPageResponseBody(body *VironPageResponseBody) (err error) {
	if body.Components == nil {
		err = goa.MergeErrors(err, goa.MissingFieldError("components", "body"))
	}
	for _, e := range body.Components {
		if e != nil {
			if err2 := ValidateVironComponentResponseBody(e); err2 != nil {
				err = goa.MergeErrors(err, err2)
			}
		}
	}
	return
}

func ValidateVironComponentResponseBody(body *VironComponentResponseBody) (err error) {
	if body.API == nil {
		err = goa.MergeErrors(err, goa.MissingFieldError("api", "body"))
	}
	if !(body.Style == "number" || body.Style == "table" || body.Style == "graph-bar" || body.Style == "graph-scatterplot" || body.Style == "graph-line" || body.Style == "graph-horizontal-bar" || body.Style == "graph-stacked-bar" || body.Style == "graph-horizontal-stacked-bar" || body.Style == "graph-stacked-area") {
		err = goa.MergeErrors(err, goa.InvalidEnumValueError("body.style", body.Style, []interface{}{"number", "table", "graph-bar", "graph-scatterplot", "graph-line", "graph-horizontal-bar", "graph-stacked-bar", "graph-horizontal-stacked-bar", "graph-stacked-area"}))
	}
	return
}
// Code generated by goa v2.0.0-wip, DO NOT EDIT.
//
// viron HTTP server types
//
// Command:
// $ goa gen github.com/andmorefine/buddha/design

package server

import (
	vironviews "github.com/andmorefine/buddha/gen/viron/views"
	goa "goa.design/goa"
)

// VironAuthtypeResponseCollection is the type of the "viron" service
// "authtype" endpoint HTTP response body.
type VironAuthtypeResponseCollection []*VironAuthtypeResponse

// VironMenuResponseBody is the type of the "viron" service "viron_menu"
// endpoint HTTP response body.
type VironMenuResponseBody struct {
	Name      string                   `form:"name" json:"name" xml:"name"`
	Thumbnail *string                  `form:"thumbnail,omitempty" json:"thumbnail,omitempty" xml:"thumbnail,omitempty"`
	Tags      []string                 `form:"tags,omitempty" json:"tags,omitempty" xml:"tags,omitempty"`
	Color     *string                  `form:"color,omitempty" json:"color,omitempty" xml:"color,omitempty"`
	Theme     *string                  `form:"theme,omitempty" json:"theme,omitempty" xml:"theme,omitempty"`
	Pages     []*VironPageResponseBody `form:"pages" json:"pages" xml:"pages"`
}

// VironAuthtypeResponse is used to define fields on response body types.
type VironAuthtypeResponse struct {
	// type name
	Type string `form:"type" json:"type" xml:"type"`
	// provider name
	Provider string `form:"provider" json:"provider" xml:"provider"`
	// url
	URL string `form:"url" json:"url" xml:"url"`
	// request method to submit this auth
	Method string `form:"method" json:"method" xml:"method"`
}

// VironPageResponseBody is used to define fields on response body types.
type VironPageResponseBody struct {
	Section    string                        `form:"section" json:"section" xml:"section"`
	Group      *string                       `form:"group,omitempty" json:"group,omitempty" xml:"group,omitempty"`
	ID         string                        `form:"id" json:"id" xml:"id"`
	Name       string                        `form:"name" json:"name" xml:"name"`
	Components []*VironComponentResponseBody `form:"components" json:"components" xml:"components"`
}

// VironComponentResponseBody is used to define fields on response body types.
type VironComponentResponseBody struct {
	Name           string                    `form:"name" json:"name" xml:"name"`
	Style          string                    `form:"style" json:"style" xml:"style"`
	Unit           *string                   `form:"unit,omitempty" json:"unit,omitempty" xml:"unit,omitempty"`
	Actions        []string                  `form:"actions,omitempty" json:"actions,omitempty" xml:"actions,omitempty"`
	API            *VironAPIResponseBody     `form:"api" json:"api" xml:"api"`
	Pagination     *bool                     `form:"pagination,omitempty" json:"pagination,omitempty" xml:"pagination,omitempty"`
	Primary        *string                   `form:"primary,omitempty" json:"primary,omitempty" xml:"primary,omitempty"`
	TableLabels    []string                  `form:"table_labels,omitempty" json:"table_labels,omitempty" xml:"table_labels,omitempty"`
	Query          []*VironQueryResponseBody `form:"query,omitempty" json:"query,omitempty" xml:"query,omitempty"`
	AutoRefreshSec *int32                    `form:"auto_refresh_sec,omitempty" json:"auto_refresh_sec,omitempty" xml:"auto_refresh_sec,omitempty"`
}

// VironAPIResponseBody is used to define fields on response body types.
type VironAPIResponseBody struct {
	Method string `form:"method" json:"method" xml:"method"`
	Path   string `form:"path" json:"path" xml:"path"`
}

// VironQueryResponseBody is used to define fields on response body types.
type VironQueryResponseBody struct {
	Key  string `form:"key" json:"key" xml:"key"`
	Type string `form:"type" json:"type" xml:"type"`
}

// NewVironAuthtypeResponseCollection builds the HTTP response body from the
// result of the "authtype" endpoint of the "viron" service.
func NewVironAuthtypeResponseCollection(res vironviews.VironAuthtypeCollectionView) VironAuthtypeResponseCollection {
	body := make([]*VironAuthtypeResponse, len(res))
	for i, val := range res {
		body[i] = &VironAuthtypeResponse{
			Type:     *val.Type,
			Provider: *val.Provider,
			URL:      *val.URL,
			Method:   *val.Method,
		}
	}
	return body
}

// NewVironMenuResponseBody builds the HTTP response body from the result of
// the "viron_menu" endpoint of the "viron" service.
func NewVironMenuResponseBody(res *vironviews.VironMenuView) *VironMenuResponseBody {
	body := &VironMenuResponseBody{
		Name:      *res.Name,
		Thumbnail: res.Thumbnail,
		Color:     res.Color,
		Theme:     res.Theme,
	}
	if res.Tags != nil {
		body.Tags = make([]string, len(res.Tags))
		for i, val := range res.Tags {
			body.Tags[i] = val
		}
	}
	if res.Pages != nil {
		body.Pages = make([]*VironPageResponseBody, len(res.Pages))
		for i, val := range res.Pages {
			body.Pages[i] = &VironPageResponseBody{
				ID:      *val.ID,
				Name:    *val.Name,
				Section: *val.Section,
				Group:   val.Group,
			}
			if val.Components != nil {
				body.Pages[i].Components = make([]*VironComponentResponseBody, len(val.Components))
				for j, val := range val.Components {
					body.Pages[i].Components[j] = &VironComponentResponseBody{
						Name:           *val.Name,
						Style:          *val.Style,
						Unit:           val.Unit,
						Pagination:     val.Pagination,
						Primary:        val.Primary,
						AutoRefreshSec: val.AutoRefreshSec,
					}
					if val.Actions != nil {
						body.Pages[i].Components[j].Actions = make([]string, len(val.Actions))
						for k, val := range val.Actions {
							body.Pages[i].Components[j].Actions[k] = val
						}
					}
					if val.API != nil {
						body.Pages[i].Components[j].API = marshalVironAPIViewToVironAPIResponseBody(val.API)
					}
					if val.TableLabels != nil {
						body.Pages[i].Components[j].TableLabels = make([]string, len(val.TableLabels))
						for k, val := range val.TableLabels {
							body.Pages[i].Components[j].TableLabels[k] = val
						}
					}
					if val.Query != nil {
						body.Pages[i].Components[j].Query = make([]*VironQueryResponseBody, len(val.Query))
						for k, val := range val.Query {
							body.Pages[i].Components[j].Query[k] = &VironQueryResponseBody{
								Key:  *val.Key,
								Type: *val.Type,
							}
						}
					}
				}
			}
		}
	}
	return body
}

// ValidateVironPageResponseBody runs the validations defined on
// Viron_pageResponseBody
func ValidateVironPageResponseBody(body *VironPageResponseBody) (err error) {
	if body.Components == nil {
		err = goa.MergeErrors(err, goa.MissingFieldError("components", "body"))
	}
	for _, e := range body.Components {
		if e != nil {
			if err2 := ValidateVironComponentResponseBody(e); err2 != nil {
				err = goa.MergeErrors(err, err2)
			}
		}
	}
	return
}

// ValidateVironComponentResponseBody runs the validations defined on
// Viron_componentResponseBody
func ValidateVironComponentResponseBody(body *VironComponentResponseBody) (err error) {
	if body.API == nil {
		err = goa.MergeErrors(err, goa.MissingFieldError("api", "body"))
	}
	if !(body.Style == "number" || body.Style == "table" || body.Style == "graph-bar" || body.Style == "graph-scatterplot" || body.Style == "graph-line" || body.Style == "graph-horizontal-bar" || body.Style == "graph-stacked-bar" || body.Style == "graph-horizontal-stacked-bar" || body.Style == "graph-stacked-area") {
		err = goa.MergeErrors(err, goa.InvalidEnumValueError("body.style", body.Style, []interface{}{"number", "table", "graph-bar", "graph-scatterplot", "graph-line", "graph-horizontal-bar", "graph-stacked-bar", "graph-horizontal-stacked-bar", "graph-stacked-area"}))
	}
	return
}
