// Package pattern provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT.
package pattern

import (
	"encoding/json"
	"fmt"

	core "github.com/meshery/schemas/models/core"
	catalogv1beta1 "github.com/meshery/schemas/models/v1beta1/catalog"
	component "github.com/meshery/schemas/models/v1beta1/component"
	relationship "github.com/meshery/schemas/models/v1beta2/relationship"
	"github.com/oapi-codegen/runtime"
)

// DesignPreferences Design-level preferences
type DesignPreferences struct {
	// Layers Map of available layers, where keys are layer names.
	Layers map[string]interface{} `json:"layers" yaml:"layers"`
}

// CatalogContentClass defines model for CatalogContentClass.
type CatalogContentClass struct {
	Class                *string                `json:"class,omitempty" yaml:"class,omitempty"`
	Description          *string                `json:"description,omitempty" yaml:"description,omitempty"`
	AdditionalProperties map[string]interface{} `json:"-" yaml:"-"`
}

// CatalogContentItem defines model for CatalogContentItem.
type CatalogContentItem map[string]interface{}

// CatalogContentPage defines model for CatalogContentPage.
type CatalogContentPage struct {
	CategoryCount *[]map[string]interface{} `json:"categoryCount,omitempty" yaml:"categoryCount,omitempty"`
	Filters       *[]MesheryFilter          `json:"filters,omitempty" yaml:"filters,omitempty"`
	ModelsCount   *[]map[string]interface{} `json:"modelsCount,omitempty" yaml:"modelsCount,omitempty"`
	Page          *int                      `json:"page,omitempty" yaml:"page,omitempty"`
	PageSize      *int                      `json:"page_size,omitempty" yaml:"page_size,omitempty"`
	Patterns      *[]MesheryPattern         `json:"patterns,omitempty" yaml:"patterns,omitempty"`
	TotalCount    *int                      `json:"total_count,omitempty" yaml:"total_count,omitempty"`
}

// CatalogRequest defines model for CatalogRequest.
type CatalogRequest map[string]interface{}

// CatalogRequestsPage defines model for CatalogRequestsPage.
type CatalogRequestsPage struct {
	CatalogRequests *[]CatalogRequest `json:"catalogRequests,omitempty" yaml:"catalogRequests,omitempty"`
	Page            *int              `json:"page,omitempty" yaml:"page,omitempty"`
	PageSize        *int              `json:"page_size,omitempty" yaml:"page_size,omitempty"`
	TotalCount      *int              `json:"total_count,omitempty" yaml:"total_count,omitempty"`
}

// DeletePatternModel defines model for DeletePatternModel.
type DeletePatternModel struct {
	ID   core.Id   `json:"id,omitempty" yaml:"id,omitempty"`
	Name core.Text `json:"name,omitempty" yaml:"name,omitempty"`
}

// MesheryFilter defines model for MesheryFilter.
type MesheryFilter map[string]interface{}

// MesheryPattern defines model for MesheryPattern.
type MesheryPattern struct {
	CatalogData *catalogv1beta1.CatalogData `json:"catalogData,omitempty" yaml:"catalogData,omitempty"`
	CreatedAt   core.Time         `json:"created_at,omitempty" yaml:"created_at,omitempty"`
	ID          core.Id           `json:"id,omitempty" yaml:"id,omitempty"`
	Location    core.MapObject    `json:"location,omitempty" yaml:"location,omitempty"`
	Name        core.Text         `json:"name,omitempty" yaml:"name,omitempty"`

	// PatternFile Designs are your primary tool for collaborative authorship of your infrastructure, workflow, and processes.
	PatternFile *PatternFile      `json:"patternFile,omitempty" yaml:"patternFile,omitempty"`
	UpdatedAt   core.Time `json:"updated_at,omitempty" yaml:"updated_at,omitempty"`
	UserId      core.Id   `json:"user_id,omitempty" yaml:"user_id,omitempty"`
	Visibility  core.Text `json:"visibility,omitempty" yaml:"visibility,omitempty"`
}

// MesheryPatternDeleteRequestBody defines model for MesheryPatternDeleteRequestBody.
type MesheryPatternDeleteRequestBody struct {
	Patterns *[]DeletePatternModel `json:"patterns,omitempty" yaml:"patterns,omitempty"`
}

// MesheryPatternImportFilePayload Upload a design file from the local system. Both `file` and `file_name` are required; the server uses the file name to identify the file type (Kubernetes Manifest, Helm Chart, Docker Compose, or Meshery Design).
type MesheryPatternImportFilePayload struct {
	// File Base64-encoded file bytes. Supported formats: Kubernetes Manifests, Helm Charts, Docker Compose, and Meshery Designs. See [Import Designs Documentation](https://docs.meshery.io/guides/configuration-management/importing-designs#import-designs-using-meshery-ui) for details.
	File []byte `json:"file" yaml:"file"`

	// FileName The name of the pattern file being imported. Include the extension (e.g. `design.yaml`), as the server uses it to identify the file type.
	FileName string `json:"file_name" yaml:"file_name"`

	// Name Provide a name for your design. This name will help you identify the design later. You can also change the name of your design after importing it.
	Name *string `json:"name,omitempty" yaml:"name,omitempty"`
}

// MesheryPatternImportRequestBody Body for POST /api/pattern/import. Consumed by the server as application/json. Exactly one of two variants must be supplied: a File Import carrying base64-encoded bytes plus a file name, or a URL Import naming a remote location the server will fetch. Sending both variants at once, or neither, is rejected with 400.
type MesheryPatternImportRequestBody struct {
	union json.RawMessage
}

// MesheryPatternImportURLPayload Import a design by URL. The server will fetch the resource and derive the file type from the response.
type MesheryPatternImportURLPayload struct {
	// Name Provide a name for your design. This name will help you identify the design later. You can also change the name of your design after importing it.
	Name *string `json:"name,omitempty" yaml:"name,omitempty"`

	// Url A direct URL to a single file, for example: https://raw.github.com/your-design-file.yaml. Ensure the resource is in a supported format: Kubernetes Manifest, Helm Chart, Docker Compose, or Meshery Design. See [Import Designs Documentation](https://docs.meshery.io/guides/configuration-management/importing-designs#import-designs-using-meshery-ui) for details.
	Url string `json:"url" yaml:"url"`
}

// MesheryPatternPage defines model for MesheryPatternPage.
type MesheryPatternPage struct {
	Page       *int              `json:"page,omitempty" yaml:"page,omitempty"`
	PageSize   *int              `json:"page_size,omitempty" yaml:"page_size,omitempty"`
	Patterns   *[]MesheryPattern `json:"patterns,omitempty" yaml:"patterns,omitempty"`
	ResultType *string           `json:"resultType,omitempty" yaml:"resultType,omitempty"`
	TotalCount *int              `json:"total_count,omitempty" yaml:"total_count,omitempty"`
}

// MesheryPatternRequestBody defines model for MesheryPatternRequestBody.
type MesheryPatternRequestBody struct {
	Name        *string               `json:"name,omitempty" yaml:"name,omitempty"`
	Path        core.Text     `json:"path,omitempty" yaml:"path,omitempty"`
	PatternData *MesheryPattern       `json:"patternData,omitempty" yaml:"patternData,omitempty"`
	Save        *bool                 `json:"save,omitempty" yaml:"save,omitempty"`
	Url         core.Endpoint `json:"url,omitempty" yaml:"url,omitempty"`
}

// PatternFile Designs are your primary tool for collaborative authorship of your infrastructure, workflow, and processes.
type PatternFile struct {
	// Id A Universally Unique Identifier used to uniquely identify entities in Meshery. The UUID core definition is used across different schemas.
	ID core.Uuid `json:"id" yaml:"id"`

	// Name Name of the design; a descriptive, but concise title for the design document.
	Name string `json:"name" yaml:"name"`

	// SchemaVersion API version of the object, optionally prefixed with an API group (e.g. "group.example.io/v1beta1" or bare "v1beta1").
	SchemaVersion core.VersionString `json:"schemaVersion" yaml:"schemaVersion"`

	// Version A valid semantic version string between 5 and 100 characters. The pattern allows for a major.minor.patch version followed by an optional pre-release tag like '-alpha' or '-beta.2' and an optional build metadata tag like '+build.1'.
	Version  core.SemverString `json:"version" yaml:"version"`
	Metadata *PatternFile_Metadata     `json:"metadata,omitempty" yaml:"metadata,omitempty"`

	// Components A list of one or more component declarations.
	Components []*component.ComponentDefinition `json:"components" yaml:"components"`

	// Preferences Design-level preferences
	Preferences *DesignPreferences `json:"preferences,omitempty" yaml:"preferences,omitempty"`

	// Relationships List of relationships between components
	Relationships []*relationship.RelationshipDefinition `json:"relationships" yaml:"relationships"`
}

// PatternFile_Metadata defines model for PatternFile.Metadata.
type PatternFile_Metadata struct {
	// ResolvedAliases Map of resolved aliases present in the design
	ResolvedAliases      *map[string]core.ResolvedAlias `json:"resolvedAliases,omitempty" yaml:"resolvedAliases,omitempty"`
	AdditionalProperties map[string]interface{}         `json:"-" yaml:"-"`
}

// ResourceAccessActorsResponse defines model for ResourceAccessActorsResponse.
type ResourceAccessActorsResponse struct {
	Users *[]map[string]interface{} `json:"users,omitempty" yaml:"users,omitempty"`
}

// ResourceAccessMapping defines model for ResourceAccessMapping.
type ResourceAccessMapping map[string]interface{}

// Id A Universally Unique Identifier used to uniquely identify entities in Meshery. The UUID core definition is used across different schemas.
type Id = core.Uuid

// Order defines model for order.
type Order = string

// Page defines model for page.
type Page = string

// Pagesize defines model for pagesize.
type Pagesize = string

// Search defines model for search.
type Search = string

// CatalogContentPayload defines model for catalogContentPayload.
type CatalogContentPayload map[string]interface{}

// ResourceSharePayload defines model for resourceSharePayload.
type ResourceSharePayload map[string]interface{}

// Getter for additional properties for CatalogContentClass. Returns the specified
// element and whether it was found
func (a CatalogContentClass) Get(fieldName string) (value interface{}, found bool) {
	if a.AdditionalProperties != nil {
		value, found = a.AdditionalProperties[fieldName]
	}
	return
}

// Setter for additional properties for CatalogContentClass
func (a *CatalogContentClass) Set(fieldName string, value interface{}) {
	if a.AdditionalProperties == nil {
		a.AdditionalProperties = make(map[string]interface{})
	}
	a.AdditionalProperties[fieldName] = value
}

// Override default JSON handling for CatalogContentClass to handle AdditionalProperties
func (a *CatalogContentClass) UnmarshalJSON(b []byte) error {
	object := make(map[string]json.RawMessage)
	err := json.Unmarshal(b, &object)
	if err != nil {
		return err
	}

	if raw, found := object["class"]; found {
		err = json.Unmarshal(raw, &a.Class)
		if err != nil {
			return fmt.Errorf("error reading 'class': %w", err)
		}
		delete(object, "class")
	}

	if raw, found := object["description"]; found {
		err = json.Unmarshal(raw, &a.Description)
		if err != nil {
			return fmt.Errorf("error reading 'description': %w", err)
		}
		delete(object, "description")
	}

	if len(object) != 0 {
		a.AdditionalProperties = make(map[string]interface{})
		for fieldName, fieldBuf := range object {
			var fieldVal interface{}
			err := json.Unmarshal(fieldBuf, &fieldVal)
			if err != nil {
				return fmt.Errorf("error unmarshaling field %s: %w", fieldName, err)
			}
			a.AdditionalProperties[fieldName] = fieldVal
		}
	}
	return nil
}

// Override default JSON handling for CatalogContentClass to handle AdditionalProperties
func (a CatalogContentClass) MarshalJSON() ([]byte, error) {
	var err error
	object := make(map[string]json.RawMessage)

	if a.Class != nil {
		object["class"], err = json.Marshal(a.Class)
		if err != nil {
			return nil, fmt.Errorf("error marshaling 'class': %w", err)
		}
	}

	if a.Description != nil {
		object["description"], err = json.Marshal(a.Description)
		if err != nil {
			return nil, fmt.Errorf("error marshaling 'description': %w", err)
		}
	}

	for fieldName, field := range a.AdditionalProperties {
		object[fieldName], err = json.Marshal(field)
		if err != nil {
			return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err)
		}
	}
	return json.Marshal(object)
}

// Getter for additional properties for PatternFile_Metadata. Returns the specified
// element and whether it was found
func (a PatternFile_Metadata) Get(fieldName string) (value interface{}, found bool) {
	if a.AdditionalProperties != nil {
		value, found = a.AdditionalProperties[fieldName]
	}
	return
}

// Setter for additional properties for PatternFile_Metadata
func (a *PatternFile_Metadata) Set(fieldName string, value interface{}) {
	if a.AdditionalProperties == nil {
		a.AdditionalProperties = make(map[string]interface{})
	}
	a.AdditionalProperties[fieldName] = value
}

// Override default JSON handling for PatternFile_Metadata to handle AdditionalProperties
func (a *PatternFile_Metadata) UnmarshalJSON(b []byte) error {
	object := make(map[string]json.RawMessage)
	err := json.Unmarshal(b, &object)
	if err != nil {
		return err
	}

	if raw, found := object["resolvedAliases"]; found {
		err = json.Unmarshal(raw, &a.ResolvedAliases)
		if err != nil {
			return fmt.Errorf("error reading 'resolvedAliases': %w", err)
		}
		delete(object, "resolvedAliases")
	}

	if len(object) != 0 {
		a.AdditionalProperties = make(map[string]interface{})
		for fieldName, fieldBuf := range object {
			var fieldVal interface{}
			err := json.Unmarshal(fieldBuf, &fieldVal)
			if err != nil {
				return fmt.Errorf("error unmarshaling field %s: %w", fieldName, err)
			}
			a.AdditionalProperties[fieldName] = fieldVal
		}
	}
	return nil
}

// Override default JSON handling for PatternFile_Metadata to handle AdditionalProperties
func (a PatternFile_Metadata) MarshalJSON() ([]byte, error) {
	var err error
	object := make(map[string]json.RawMessage)

	if a.ResolvedAliases != nil {
		object["resolvedAliases"], err = json.Marshal(a.ResolvedAliases)
		if err != nil {
			return nil, fmt.Errorf("error marshaling 'resolvedAliases': %w", err)
		}
	}

	for fieldName, field := range a.AdditionalProperties {
		object[fieldName], err = json.Marshal(field)
		if err != nil {
			return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err)
		}
	}
	return json.Marshal(object)
}

// AsMesheryPatternImportFilePayload returns the union data inside the MesheryPatternImportRequestBody as a MesheryPatternImportFilePayload
func (t MesheryPatternImportRequestBody) AsMesheryPatternImportFilePayload() (MesheryPatternImportFilePayload, error) {
	var body MesheryPatternImportFilePayload
	err := json.Unmarshal(t.union, &body)
	return body, err
}

// FromMesheryPatternImportFilePayload overwrites any union data inside the MesheryPatternImportRequestBody as the provided MesheryPatternImportFilePayload
func (t *MesheryPatternImportRequestBody) FromMesheryPatternImportFilePayload(v MesheryPatternImportFilePayload) error {
	b, err := json.Marshal(v)
	t.union = b
	return err
}

// MergeMesheryPatternImportFilePayload performs a merge with any union data inside the MesheryPatternImportRequestBody, using the provided MesheryPatternImportFilePayload
func (t *MesheryPatternImportRequestBody) MergeMesheryPatternImportFilePayload(v MesheryPatternImportFilePayload) error {
	b, err := json.Marshal(v)
	if err != nil {
		return err
	}

	merged, err := runtime.JSONMerge(t.union, b)
	t.union = merged
	return err
}

// AsMesheryPatternImportURLPayload returns the union data inside the MesheryPatternImportRequestBody as a MesheryPatternImportURLPayload
func (t MesheryPatternImportRequestBody) AsMesheryPatternImportURLPayload() (MesheryPatternImportURLPayload, error) {
	var body MesheryPatternImportURLPayload
	err := json.Unmarshal(t.union, &body)
	return body, err
}

// FromMesheryPatternImportURLPayload overwrites any union data inside the MesheryPatternImportRequestBody as the provided MesheryPatternImportURLPayload
func (t *MesheryPatternImportRequestBody) FromMesheryPatternImportURLPayload(v MesheryPatternImportURLPayload) error {
	b, err := json.Marshal(v)
	t.union = b
	return err
}

// MergeMesheryPatternImportURLPayload performs a merge with any union data inside the MesheryPatternImportRequestBody, using the provided MesheryPatternImportURLPayload
func (t *MesheryPatternImportRequestBody) MergeMesheryPatternImportURLPayload(v MesheryPatternImportURLPayload) error {
	b, err := json.Marshal(v)
	if err != nil {
		return err
	}

	merged, err := runtime.JSONMerge(t.union, b)
	t.union = merged
	return err
}

func (t MesheryPatternImportRequestBody) MarshalJSON() ([]byte, error) {
	b, err := t.union.MarshalJSON()
	return b, err
}

func (t *MesheryPatternImportRequestBody) UnmarshalJSON(b []byte) error {
	err := t.union.UnmarshalJSON(b)
	return err
}
