// Package event 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 event

import (
	"encoding/json"
	"fmt"
	"time"

	"github.com/gofrs/uuid"
	core "github.com/meshery/schemas/models/core"
)

// BulkDeleteRequest Payload for bulk-deleting events by ID.
type BulkDeleteRequest struct {
	// Ids UUIDs of the events to delete.
	Ids []core.Uuid `json:"ids" yaml:"ids"`
}

// BulkDeleteResponse Response body returned after bulk event deletion.
type BulkDeleteResponse struct {
	// Deleted UUIDs of events that were deleted.
	Deleted *[]uuid.UUID `json:"deleted,omitempty" yaml:"deleted,omitempty"`
}

// BulkUpdateStatusRequest Payload for bulk-updating the status of events.
type BulkUpdateStatusRequest struct {
	// Ids UUIDs of the events to update.
	Ids []core.Uuid `json:"ids" yaml:"ids"`

	// Status New status to apply to the selected events.
	Status string `json:"status" yaml:"status"`
}

// BulkUpdateStatusResponse Response body returned after bulk event status update.
type BulkUpdateStatusResponse struct {
	// Updated UUIDs of events whose status was updated.
	Updated *[]uuid.UUID `json:"updated,omitempty" yaml:"updated,omitempty"`
}

// ErrorResponse Generic error envelope returned for non-2xx responses.
type ErrorResponse struct {
	// Error Human-readable error message.
	Error *string `json:"error,omitempty" yaml:"error,omitempty"`
}

// EventPayload Payload for creating a new event.
type EventPayload struct {
	// Action The action of the event.
	Action *string `json:"action,omitempty" yaml:"action,omitempty"`

	// Category The category of the event.
	Category *string `json:"category,omitempty" yaml:"category,omitempty"`

	// Description Description of the event.
	Description *string `json:"description,omitempty" yaml:"description,omitempty"`

	// Owner UUID of the user associated with the event.
	Owner                *uuid.UUID             `db:"owner" json:"owner,omitempty" yaml:"owner,omitempty"`
	AdditionalProperties map[string]interface{} `json:"-" yaml:"-"`
}

// EventResult EventResult entity schema.
type EventResult struct {
	// Action The action of the event.
	Action string `json:"action" yaml:"action"`

	// Category The category of the event.
	Category string `json:"category" yaml:"category"`

	// CreatedAt Timestamp when the event was recorded.
	CreatedAt time.Time `db:"created_at" json:"createdAt" yaml:"createdAt"`

	// Description Description of the event.
	Description *string `json:"description,omitempty" yaml:"description,omitempty"`

	// Email email
	Email core.Email `json:"email,omitempty" yaml:"email,omitempty"`

	// FirstName The first name of the user associated with the event.
	FirstName *string `json:"firstName,omitempty" yaml:"firstName,omitempty"`

	// LastName The last name of the user associated with the event.
	LastName *string `json:"lastName,omitempty" yaml:"lastName,omitempty"`

	// Owner UUID of the user associated with the event.
	Owner uuid.UUID `db:"owner" json:"owner" yaml:"owner"`

	// Provider One of (x-oapi-codegen-extra-tags-cloud, github, google)
	Provider core.Provider `json:"provider,omitempty" yaml:"provider,omitempty"`

	// SystemId System identifier of the event source.
	SystemId string `db:"system_id" json:"systemId" yaml:"systemId"`
}

// EventSummary Per-user event summary entry.
type EventSummary map[string]interface{}

// EventSummaryPage Paginated list of per-user event summaries.
type EventSummaryPage struct {
	// Data The event summaries returned on the current page.
	Data *[]EventSummary `json:"data,omitempty" yaml:"data,omitempty"`

	// Page Current page number of the result set.
	Page *int `json:"page,omitempty" yaml:"page,omitempty"`

	// PageSize Number of items per page.
	PageSize *int `json:"pageSize,omitempty" yaml:"pageSize,omitempty"`

	// TotalCount Total number of items available.
	TotalCount *int `json:"totalCount,omitempty" yaml:"totalCount,omitempty"`
}

// EventType A category/action pair describing one kind of event.
type EventType struct {
	// Action The action of the event type.
	Action *string `json:"action,omitempty" yaml:"action,omitempty"`

	// Category The category of the event type.
	Category *string `json:"category,omitempty" yaml:"category,omitempty"`
}

// EventsAggregate Aggregated event counts across categories.
type EventsAggregate struct {
	// Audit Count of audit-category events.
	Audit                *int                   `json:"audit,omitempty" yaml:"audit,omitempty"`
	AdditionalProperties map[string]interface{} `json:"-" yaml:"-"`
}

// EventsPage Paginated list of events.
type EventsPage struct {
	// Data The events returned on the current page.
	Data       *[]EventResult      `json:"data,omitempty" yaml:"data,omitempty"`
	Page       core.Number `json:"page,omitempty" yaml:"page,omitempty"`
	PageSize   core.Number `json:"pageSize,omitempty" yaml:"pageSize,omitempty"`
	TotalCount core.Number `json:"totalCount,omitempty" yaml:"totalCount,omitempty"`
}

// UpdateEventStatusRequest Payload for updating the status of a single event.
type UpdateEventStatusRequest struct {
	// Status Current status of the event.
	Status string `json:"status" yaml:"status"`
}

// UpdateEventStatusResponse Response body returned after updating an event's status.
type UpdateEventStatusResponse struct {
	// EventId UUID of the event whose status was updated.
	EventId *uuid.UUID `json:"eventId,omitempty" yaml:"eventId,omitempty"`

	// Message Human-readable status message.
	Message *string `json:"message,omitempty" yaml:"message,omitempty"`

	// Status Updated status of the event.
	Status *string `json:"status,omitempty" yaml:"status,omitempty"`
}

// Cumulative defines model for cumulative.
type Cumulative = bool

// EventId defines model for eventId.
type EventId = uuid.UUID

// Filter defines model for filter.
type Filter = string

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

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

// PageSize defines model for pageSize.
type PageSize = int

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

// PagesizeLegacy defines model for pagesizeLegacy.
type PagesizeLegacy = int

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

// WorkspaceId defines model for workspaceId.
type WorkspaceId = core.WorkspaceId

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

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

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

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

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

	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 raw, found := object["owner"]; found {
		err = json.Unmarshal(raw, &a.Owner)
		if err != nil {
			return fmt.Errorf("error reading 'owner': %w", err)
		}
		delete(object, "owner")
	}

	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 EventPayload to handle AdditionalProperties
func (a EventPayload) MarshalJSON() ([]byte, error) {
	var err error
	object := make(map[string]json.RawMessage)

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

	if a.Category != nil {
		object["category"], err = json.Marshal(a.Category)
		if err != nil {
			return nil, fmt.Errorf("error marshaling 'category': %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)
		}
	}

	if a.Owner != nil {
		object["owner"], err = json.Marshal(a.Owner)
		if err != nil {
			return nil, fmt.Errorf("error marshaling 'owner': %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 EventsAggregate. Returns the specified
// element and whether it was found
func (a EventsAggregate) Get(fieldName string) (value interface{}, found bool) {
	if a.AdditionalProperties != nil {
		value, found = a.AdditionalProperties[fieldName]
	}
	return
}

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

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

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

	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 EventsAggregate to handle AdditionalProperties
func (a EventsAggregate) MarshalJSON() ([]byte, error) {
	var err error
	object := make(map[string]json.RawMessage)

	if a.Audit != nil {
		object["audit"], err = json.Marshal(a.Audit)
		if err != nil {
			return nil, fmt.Errorf("error marshaling 'audit': %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)
}
