package mcp

import (
	
	

	
)

// ClientRequest types
var (
	_ ClientRequest = (*PingRequest)(nil)
	_ ClientRequest = (*InitializeRequest)(nil)
	_ ClientRequest = (*CompleteRequest)(nil)
	_ ClientRequest = (*SetLevelRequest)(nil)
	_ ClientRequest = (*GetPromptRequest)(nil)
	_ ClientRequest = (*ListPromptsRequest)(nil)
	_ ClientRequest = (*ListResourcesRequest)(nil)
	_ ClientRequest = (*ReadResourceRequest)(nil)
	_ ClientRequest = (*SubscribeRequest)(nil)
	_ ClientRequest = (*UnsubscribeRequest)(nil)
	_ ClientRequest = (*CallToolRequest)(nil)
	_ ClientRequest = (*ListToolsRequest)(nil)
)

// ClientNotification types
var (
	_ ClientNotification = (*CancelledNotification)(nil)
	_ ClientNotification = (*ProgressNotification)(nil)
	_ ClientNotification = (*InitializedNotification)(nil)
	_ ClientNotification = (*RootsListChangedNotification)(nil)
)

// ClientResult types
var (
	_ ClientResult = (*EmptyResult)(nil)
	_ ClientResult = (*CreateMessageResult)(nil)
	_ ClientResult = (*ListRootsResult)(nil)
)

// ServerRequest types
var (
	_ ServerRequest = (*PingRequest)(nil)
	_ ServerRequest = (*CreateMessageRequest)(nil)
	_ ServerRequest = (*ListRootsRequest)(nil)
)

// ServerNotification types
var (
	_ ServerNotification = (*CancelledNotification)(nil)
	_ ServerNotification = (*ProgressNotification)(nil)
	_ ServerNotification = (*LoggingMessageNotification)(nil)
	_ ServerNotification = (*ResourceUpdatedNotification)(nil)
	_ ServerNotification = (*ResourceListChangedNotification)(nil)
	_ ServerNotification = (*ToolListChangedNotification)(nil)
	_ ServerNotification = (*PromptListChangedNotification)(nil)
)

// ServerResult types
var (
	_ ServerResult = (*EmptyResult)(nil)
	_ ServerResult = (*InitializeResult)(nil)
	_ ServerResult = (*CompleteResult)(nil)
	_ ServerResult = (*GetPromptResult)(nil)
	_ ServerResult = (*ListPromptsResult)(nil)
	_ ServerResult = (*ListResourcesResult)(nil)
	_ ServerResult = (*ReadResourceResult)(nil)
	_ ServerResult = (*CallToolResult)(nil)
	_ ServerResult = (*ListToolsResult)(nil)
)

// Helper functions for type assertions

// asType attempts to cast the given interface to the given type
func asType[ any]( any) (*, bool) {
	,  := .()
	if ! {
		return nil, false
	}
	return &, true
}

// AsTextContent attempts to cast the given interface to TextContent
func ( any) (*TextContent, bool) {
	return asType[TextContent]()
}

// AsImageContent attempts to cast the given interface to ImageContent
func ( any) (*ImageContent, bool) {
	return asType[ImageContent]()
}

// AsAudioContent attempts to cast the given interface to AudioContent
func ( any) (*AudioContent, bool) {
	return asType[AudioContent]()
}

// AsEmbeddedResource attempts to cast the given interface to EmbeddedResource
func ( any) (*EmbeddedResource, bool) {
	return asType[EmbeddedResource]()
}

// AsTextResourceContents attempts to cast the given interface to TextResourceContents
func ( any) (*TextResourceContents, bool) {
	return asType[TextResourceContents]()
}

// AsBlobResourceContents attempts to cast the given interface to BlobResourceContents
func ( any) (*BlobResourceContents, bool) {
	return asType[BlobResourceContents]()
}

// Helper function for JSON-RPC

// NewJSONRPCResponse creates a new JSONRPCResponse with the given id and result.
// NOTE: This function expects a Result struct, but JSONRPCResponse.Result is typed as `any`.
// The Result struct wraps the actual result data with optional metadata.
// For direct result assignment, use NewJSONRPCResultResponse instead.
func ( RequestId,  Result) JSONRPCResponse {
	return JSONRPCResponse{
		JSONRPC: JSONRPC_VERSION,
		ID:      ,
		Result:  ,
	}
}

// NewJSONRPCResultResponse creates a new JSONRPCResponse with the given id and result.
// This function accepts any type for the result, matching the JSONRPCResponse.Result field type.
func ( RequestId,  any) JSONRPCResponse {
	return JSONRPCResponse{
		JSONRPC: JSONRPC_VERSION,
		ID:      ,
		Result:  ,
	}
}

// NewJSONRPCErrorDetails creates a new JSONRPCErrorDetails with the given code, message, and data.
func ( int,  string,  any) JSONRPCErrorDetails {
	return JSONRPCErrorDetails{
		Code:    ,
		Message: ,
		Data:    ,
	}
}

// NewJSONRPCError creates a new JSONRPCResponse with the given id, code, and message
func (
	 RequestId,
	 int,
	 string,
	 any,
) JSONRPCError {
	return JSONRPCError{
		JSONRPC: JSONRPC_VERSION,
		ID:      ,
		Error:   NewJSONRPCErrorDetails(, , ),
	}
}

// NewProgressNotification
// Helper function for creating a progress notification
func (
	 ProgressToken,
	 float64,
	 *float64,
	 *string,
) ProgressNotification {
	 := ProgressNotification{
		Notification: Notification{
			Method: "notifications/progress",
		},
		Params: struct {
			 ProgressToken `json:"progressToken"`
			      float64       `json:"progress"`
			         float64       `json:"total,omitempty"`
			       string        `json:"message,omitempty"`
		}{
			: ,
			:      ,
		},
	}
	if  != nil {
		.Params.Total = *
	}
	if  != nil {
		.Params.Message = *
	}
	return 
}

// NewLoggingMessageNotification
// Helper function for creating a logging message notification
func (
	 LoggingLevel,
	 string,
	 any,
) LoggingMessageNotification {
	return LoggingMessageNotification{
		Notification: Notification{
			Method: "notifications/message",
		},
		Params: struct {
			  LoggingLevel `json:"level"`
			 string       `json:"logger,omitempty"`
			   any          `json:"data"`
		}{
			:  ,
			: ,
			:   ,
		},
	}
}

// NewPromptMessage
// Helper function to create a new PromptMessage
func ( Role,  Content) PromptMessage {
	return PromptMessage{
		Role:    ,
		Content: ,
	}
}

// NewTextContent
// Helper function to create a new TextContent
func ( string) TextContent {
	return TextContent{
		Type: ContentTypeText,
		Text: ,
	}
}

// NewImageContent
// Helper function to create a new ImageContent
func (,  string) ImageContent {
	return ImageContent{
		Type:     ContentTypeImage,
		Data:     ,
		MIMEType: ,
	}
}

// Helper function to create a new AudioContent
func (,  string) AudioContent {
	return AudioContent{
		Type:     ContentTypeAudio,
		Data:     ,
		MIMEType: ,
	}
}

// Helper function to create a new ResourceLink
func (, , ,  string) ResourceLink {
	return ResourceLink{
		Type:        ContentTypeLink,
		URI:         ,
		Name:        ,
		Description: ,
		MIMEType:    ,
	}
}

// Helper function to create a new EmbeddedResource
func ( ResourceContents) EmbeddedResource {
	return EmbeddedResource{
		Type:     ContentTypeResource,
		Resource: ,
	}
}

// NewToolResultText creates a new CallToolResult with a text content
func ( string) *CallToolResult {
	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: ContentTypeText,
				Text: ,
			},
		},
	}
}

// NewToolResultJSON creates a new CallToolResult with a JSON content.
func [ any]( ) (*CallToolResult, error) {
	,  := json.Marshal()
	if  != nil {
		return nil, fmt.Errorf("unable to marshal JSON: %w", )
	}

	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: ContentTypeText,
				Text: string(),
			},
		},
		StructuredContent: ,
	}, nil
}

// NewToolResultStructured creates a new CallToolResult with structured content.
// It includes both the structured content and a text representation for backward compatibility.
func ( any,  string) *CallToolResult {
	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: "text",
				Text: ,
			},
		},
		StructuredContent: ,
	}
}

// NewToolResultStructuredOnly creates a new CallToolResult with structured
// content and creates a JSON string fallback for backwards compatibility.
// This is useful when you want to provide structured data without any specific text fallback.
func ( any) *CallToolResult {
	var  string
	// Convert to JSON string for backward compatibility
	,  := json.Marshal()
	if  != nil {
		 = fmt.Sprintf("Error serializing structured content: %v", )
	} else {
		 = string()
	}

	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: "text",
				Text: ,
			},
		},
		StructuredContent: ,
	}
}

// NewToolResultImage creates a new CallToolResult with both text and image content
func (, ,  string) *CallToolResult {
	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: ContentTypeText,
				Text: ,
			},
			ImageContent{
				Type:     ContentTypeImage,
				Data:     ,
				MIMEType: ,
			},
		},
	}
}

// NewToolResultAudio creates a new CallToolResult with both text and audio content
func (, ,  string) *CallToolResult {
	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: ContentTypeText,
				Text: ,
			},
			AudioContent{
				Type:     ContentTypeAudio,
				Data:     ,
				MIMEType: ,
			},
		},
	}
}

// NewToolResultResource creates a new CallToolResult with an embedded resource
func (
	 string,
	 ResourceContents,
) *CallToolResult {
	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: ContentTypeText,
				Text: ,
			},
			EmbeddedResource{
				Type:     ContentTypeResource,
				Resource: ,
			},
		},
	}
}

// NewToolResultError creates a new CallToolResult with an error message.
// Any errors that originate from the tool SHOULD be reported inside the result object.
func ( string) *CallToolResult {
	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: ContentTypeText,
				Text: ,
			},
		},
		IsError: true,
	}
}

// NewToolResultErrorFromErr creates a new CallToolResult with an error message.
// If an error is provided, its details will be appended to the text message.
// Any errors that originate from the tool SHOULD be reported inside the result object.
func ( string,  error) *CallToolResult {
	if  != nil {
		 = fmt.Sprintf("%s: %v", , )
	}
	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: ContentTypeText,
				Text: ,
			},
		},
		IsError: true,
	}
}

// NewToolResultErrorf creates a new CallToolResult with an error message.
// The error message is formatted using the fmt package.
// Any errors that originate from the tool SHOULD be reported inside the result object.
func ( string,  ...any) *CallToolResult {
	return &CallToolResult{
		Content: []Content{
			TextContent{
				Type: ContentTypeText,
				Text: fmt.Sprintf(, ...),
			},
		},
		IsError: true,
	}
}

// NewListResourcesResult creates a new ListResourcesResult
func (
	 []Resource,
	 Cursor,
) *ListResourcesResult {
	return &ListResourcesResult{
		PaginatedResult: PaginatedResult{
			NextCursor: ,
		},
		Resources: ,
	}
}

// NewListResourceTemplatesResult creates a new ListResourceTemplatesResult
func (
	 []ResourceTemplate,
	 Cursor,
) *ListResourceTemplatesResult {
	return &ListResourceTemplatesResult{
		PaginatedResult: PaginatedResult{
			NextCursor: ,
		},
		ResourceTemplates: ,
	}
}

// NewReadResourceResult creates a new ReadResourceResult with text content
func ( string) *ReadResourceResult {
	return &ReadResourceResult{
		Contents: []ResourceContents{
			TextResourceContents{
				Text: ,
			},
		},
	}
}

// NewListPromptsResult creates a new ListPromptsResult
func (
	 []Prompt,
	 Cursor,
) *ListPromptsResult {
	return &ListPromptsResult{
		PaginatedResult: PaginatedResult{
			NextCursor: ,
		},
		Prompts: ,
	}
}

// NewGetPromptResult creates a new GetPromptResult
func (
	 string,
	 []PromptMessage,
) *GetPromptResult {
	return &GetPromptResult{
		Description: ,
		Messages:    ,
	}
}

// NewListToolsResult creates a new ListToolsResult
func ( []Tool,  Cursor) *ListToolsResult {
	return &ListToolsResult{
		PaginatedResult: PaginatedResult{
			NextCursor: ,
		},
		Tools: ,
	}
}

// NewInitializeResult creates a new InitializeResult
func (
	 string,
	 ServerCapabilities,
	 Implementation,
	 string,
) *InitializeResult {
	return &InitializeResult{
		ProtocolVersion: ,
		Capabilities:    ,
		ServerInfo:      ,
		Instructions:    ,
	}
}

// FormatNumberResult
// Helper for formatting numbers in tool results
func ( float64) *CallToolResult {
	return NewToolResultText(fmt.Sprintf("%.2f", ))
}

func ( map[string]any,  string) string {
	if ,  := [];  {
		if ,  := .(string);  {
			return 
		}
	}
	return ""
}

// ParseAnnotations parses priority, audience, and lastModified fields from the provided map
// and returns an Annotations struct populated with any valid values found.
// If data is nil, ParseAnnotations returns nil. Priority is set when a numeric value can be
// parsed and is stored as a *float64. Audience is populated from string values and includes
// only RoleUser and RoleAssistant entries. LastModified is set when the value is a string.
func ( map[string]any) *Annotations {
	if  == nil {
		return nil
	}
	 := &Annotations{}
	if ,  := ["priority"];  {
		if  != nil {
			if ,  := cast.ToFloat64E();  == nil {
				.Priority = &
			}
		}
	}

	if ,  := ["audience"];  {
		for ,  := range cast.ToStringSlice() {
			 := Role()
			if  == RoleUser ||  == RoleAssistant {
				.Audience = append(.Audience, )
			}
		}
	}

	if ,  := ["lastModified"];  {
		if ,  := .(string);  {
			.LastModified = 
		}
	}
	return 

}

func ( map[string]any,  string) map[string]any {
	if ,  := [];  {
		if ,  := .(map[string]any);  {
			return 
		}
	}
	return nil
}

// ParseContent parses a generic map into a strongly-typed Content value.
// It extracts annotations and _meta fields from the map and sets them on
// the returned content type.
func ( map[string]any) (Content, error) {
	 := ExtractString(, "type")

	var  *Annotations
	if  := ExtractMap(, "annotations");  != nil {
		 = ParseAnnotations()
	}

	var  *Meta
	if  := ExtractMap(, "_meta");  != nil {
		 = NewMetaFromMap()
	}

	switch  {
	case ContentTypeText:
		 := ExtractString(, "text")
		 := NewTextContent()
		.Annotations = 
		.Meta = 
		return , nil

	case ContentTypeImage:
		 := ExtractString(, "data")
		 := ExtractString(, "mimeType")
		if  == "" ||  == "" {
			return nil, fmt.Errorf("image data or mimeType is missing")
		}
		 := NewImageContent(, )
		.Annotations = 
		.Meta = 
		return , nil

	case ContentTypeAudio:
		 := ExtractString(, "data")
		 := ExtractString(, "mimeType")
		if  == "" ||  == "" {
			return nil, fmt.Errorf("audio data or mimeType is missing")
		}
		 := NewAudioContent(, )
		.Annotations = 
		.Meta = 
		return , nil

	case ContentTypeLink:
		 := ExtractString(, "uri")
		 := ExtractString(, "name")
		 := ExtractString(, "description")
		 := ExtractString(, "mimeType")
		if  == "" ||  == "" {
			return nil, fmt.Errorf("resource_link uri or name is missing")
		}
		 := NewResourceLink(, , , )
		.Annotations = 
		return , nil

	case ContentTypeResource:
		 := ExtractMap(, "resource")
		if  == nil {
			return nil, fmt.Errorf("resource is missing")
		}

		,  := ParseResourceContents()
		if  != nil {
			return nil, 
		}

		 := NewEmbeddedResource()
		.Annotations = 
		.Meta = 
		return , nil
	}

	return nil, fmt.Errorf("unsupported content type: %s", )
}

func ( *json.RawMessage) (*GetPromptResult, error) {
	if  == nil {
		return nil, fmt.Errorf("response is nil")
	}

	var  map[string]any
	if  := json.Unmarshal(*, &);  != nil {
		return nil, fmt.Errorf("failed to unmarshal response: %w", )
	}

	 := GetPromptResult{}

	,  := ["_meta"]
	if  {
		if ,  := .(map[string]any);  {
			.Meta = NewMetaFromMap()
		}
	}

	,  := ["description"]
	if  {
		if ,  := .(string);  {
			.Description = 
		}
	}

	,  := ["messages"]
	if  {
		,  := .([]any)
		if ! {
			return nil, fmt.Errorf("messages is not an array")
		}

		for ,  := range  {
			,  := .(map[string]any)
			if ! {
				return nil, fmt.Errorf("message is not an object")
			}

			// Extract role
			 := ExtractString(, "role")
			if  == "" || ( != string(RoleAssistant) &&  != string(RoleUser)) {
				return nil, fmt.Errorf("unsupported role: %s", )
			}

			// Extract content
			,  := ["content"].(map[string]any)
			if ! {
				return nil, fmt.Errorf("content is not an object")
			}

			// Process content
			,  := ParseContent()
			if  != nil {
				return nil, 
			}

			// Append processed message
			.Messages = append(.Messages, NewPromptMessage(Role(), ))

		}
	}

	return &, nil
}

func ( *json.RawMessage) (*CallToolResult, error) {
	if  == nil {
		return nil, fmt.Errorf("response is nil")
	}

	var  map[string]any
	if  := json.Unmarshal(*, &);  != nil {
		return nil, fmt.Errorf("failed to unmarshal response: %w", )
	}

	var  CallToolResult

	,  := ["_meta"]
	if  {
		if ,  := .(map[string]any);  {
			.Meta = NewMetaFromMap()
		}
	}

	,  := ["isError"]
	if  {
		if ,  := .(bool);  {
			.IsError = 
		}
	}

	,  := ["content"]
	if ! {
		return nil, fmt.Errorf("content is missing")
	}

	,  := .([]any)
	if ! {
		return nil, fmt.Errorf("content is not an array")
	}

	for ,  := range  {
		// Extract content
		,  := .(map[string]any)
		if ! {
			return nil, fmt.Errorf("content is not an object")
		}

		// Process content
		,  := ParseContent()
		if  != nil {
			return nil, 
		}

		.Content = append(.Content, )
	}

	// Handle structured content
	,  := ["structuredContent"]
	if  {
		.StructuredContent = 
	}

	return &, nil
}

func ( map[string]any) (ResourceContents, error) {
	 := ExtractString(, "uri")
	if  == "" {
		return nil, fmt.Errorf("resource uri is missing")
	}

	 := ExtractString(, "mimeType")

	 := ExtractMap(, "_meta")

	if ,  := ["_meta"];  &&  == nil {
		return nil, fmt.Errorf("_meta must be an object")
	}

	if  := ExtractString(, "text");  != "" {
		return TextResourceContents{
			Meta:     ,
			URI:      ,
			MIMEType: ,
			Text:     ,
		}, nil
	}

	if  := ExtractString(, "blob");  != "" {
		return BlobResourceContents{
			Meta:     ,
			URI:      ,
			MIMEType: ,
			Blob:     ,
		}, nil
	}

	return nil, fmt.Errorf("unsupported resource type")
}

func ( *json.RawMessage) (*ReadResourceResult, error) {
	if  == nil {
		return nil, fmt.Errorf("response is nil")
	}

	var  map[string]any
	if  := json.Unmarshal(*, &);  != nil {
		return nil, fmt.Errorf("failed to unmarshal response: %w", )
	}

	var  ReadResourceResult

	,  := ["_meta"]
	if  {
		if ,  := .(map[string]any);  {
			.Meta = NewMetaFromMap()
		}
	}

	,  := ["contents"]
	if ! {
		return nil, fmt.Errorf("contents is missing")
	}

	,  := .([]any)
	if ! {
		return nil, fmt.Errorf("contents is not an array")
	}

	for ,  := range  {
		// Extract content
		,  := .(map[string]any)
		if ! {
			return nil, fmt.Errorf("content is not an object")
		}

		// Process content
		,  := ParseResourceContents()
		if  != nil {
			return nil, 
		}

		.Contents = append(.Contents, )
	}

	return &, nil
}

func ( CallToolRequest,  string,  any) any {
	 := .GetArguments()
	if ,  := []; ! {
		return 
	} else {
		return []
	}
}

// ParseBoolean extracts and converts a boolean parameter from a CallToolRequest.
// If the key is not found in the Arguments map, the defaultValue is returned.
// The function uses cast.ToBool for conversion which handles various string representations
// such as "true", "yes", "1", etc.
func ( CallToolRequest,  string,  bool) bool {
	 := ParseArgument(, , )
	return cast.ToBool()
}

// ParseInt64 extracts and converts an int64 parameter from a CallToolRequest.
// If the key is not found in the Arguments map, the defaultValue is returned.
func ( CallToolRequest,  string,  int64) int64 {
	 := ParseArgument(, , )
	return cast.ToInt64()
}

// ParseInt32 extracts and converts an int32 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  int32) int32 {
	 := ParseArgument(, , )
	return cast.ToInt32()
}

// ParseInt16 extracts and converts an int16 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  int16) int16 {
	 := ParseArgument(, , )
	return cast.ToInt16()
}

// ParseInt8 extracts and converts an int8 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  int8) int8 {
	 := ParseArgument(, , )
	return cast.ToInt8()
}

// ParseInt extracts and converts an int parameter from a CallToolRequest.
func ( CallToolRequest,  string,  int) int {
	 := ParseArgument(, , )
	return cast.ToInt()
}

// ParseUInt extracts and converts an uint parameter from a CallToolRequest.
func ( CallToolRequest,  string,  uint) uint {
	 := ParseArgument(, , )
	return cast.ToUint()
}

// ParseUInt64 extracts and converts an uint64 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  uint64) uint64 {
	 := ParseArgument(, , )
	return cast.ToUint64()
}

// ParseUInt32 extracts and converts an uint32 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  uint32) uint32 {
	 := ParseArgument(, , )
	return cast.ToUint32()
}

// ParseUInt16 extracts and converts an uint16 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  uint16) uint16 {
	 := ParseArgument(, , )
	return cast.ToUint16()
}

// ParseUInt8 extracts and converts an uint8 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  uint8) uint8 {
	 := ParseArgument(, , )
	return cast.ToUint8()
}

// ParseFloat32 extracts and converts a float32 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  float32) float32 {
	 := ParseArgument(, , )
	return cast.ToFloat32()
}

// ParseFloat64 extracts and converts a float64 parameter from a CallToolRequest.
func ( CallToolRequest,  string,  float64) float64 {
	 := ParseArgument(, , )
	return cast.ToFloat64()
}

// ParseString extracts and converts a string parameter from a CallToolRequest.
func ( CallToolRequest,  string,  string) string {
	 := ParseArgument(, , )
	return cast.ToString()
}

// ParseStringMap extracts and converts a string map parameter from a CallToolRequest.
func ( CallToolRequest,  string,  map[string]any) map[string]any {
	 := ParseArgument(, , )
	return cast.ToStringMap()
}

// ToBoolPtr returns a pointer to the given boolean value
func ( bool) *bool {
	return &
}

// ToInt64Ptr returns a pointer to the given int64 value
func ( int64) *int64 {
	return &
}

// GetTextFromContent extracts text from a Content interface that might be a TextContent struct
// or a map[string]any that was unmarshaled from JSON. This is useful when dealing with content
// that comes from different transport layers that may handle JSON differently.
//
// This function uses fallback behavior for non-text content - it returns a string representation
// via fmt.Sprintf for any content that cannot be extracted as text. This is a lossy operation
// intended for convenience in logging and display scenarios.
//
// For strict type validation, use ParseContent() instead, which returns an error for invalid content.
func ( any) string {
	switch c := .(type) {
	case TextContent:
		return .Text
	case map[string]any:
		// Handle JSON unmarshaled content
		if ,  := ["type"];  &&  == "text" {
			if ,  := ["text"].(string);  {
				return 
			}
		}
		return fmt.Sprintf("%v", )
	case string:
		return 
	default:
		return fmt.Sprintf("%v", )
	}
}

// jsonToTask convert json content to GetTaskResult structure
func jsonToTask( map[string]any,  *GetTaskResult) {
	,  := ["taskId"]
	if  {
		if ,  := .(string);  {
			.TaskId = 
		}
	}

	,  := ["status"]
	if  {
		if ,  := .(string);  {
			.Status = TaskStatus()
		}
	}

	,  := ["statusMessage"]
	if  {
		if ,  := .(string);  {
			.StatusMessage = 
		}
	}

	,  := ["createdAt"]
	if  {
		if ,  := .(string);  {
			.CreatedAt = 
		}
	}

	,  := ["lastUpdatedAt"]
	if  {
		if ,  := .(string);  {
			.LastUpdatedAt = 
		}
	}

	,  := ["ttl"]
	if  {
		if ,  := .(float64);  {
			 := int64()
			.TTL = &
		}
	}

	,  := ["pollInterval"]
	if  {
		if ,  := .(float64);  {
			 := int64()
			.PollInterval = &
		}
	}
}

// ParseCancelTaskResult parses a JSON message and converts it to a CancelTaskResult.
func ( *json.RawMessage) (*CancelTaskResult, error) {
	if  == nil {
		return nil, fmt.Errorf("response is nil")
	}

	var  map[string]any
	if  := json.Unmarshal(*, &);  != nil {
		return nil, fmt.Errorf("failed to unmarshal response: %w", )
	}

	 := GetTaskResult{}
	jsonToTask(, &)
	 := CancelTaskResult()

	,  := ["_meta"]
	if  {
		if ,  := .(map[string]any);  {
			.Meta = NewMetaFromMap()
		}
	}

	return &, nil
}

// ParseListTasksResult parses a JSON message and converts it to a ListTasksResult.
func ( *json.RawMessage) (*ListTasksResult, error) {
	if  == nil {
		return nil, fmt.Errorf("response is nil")
	}

	var  map[string]any
	if  := json.Unmarshal(*, &);  != nil {
		return nil, fmt.Errorf("failed to unmarshal response: %w", )
	}

	 := ListTasksResult{}

	,  := ["_meta"]
	if  {
		if ,  := .(map[string]any);  {
			.Meta = NewMetaFromMap()
		}
	}

	,  := ["tasks"]
	if  {
		if ,  := .([]any);  {
			for ,  := range  {
				if ,  := .(map[string]any);  {
					 := GetTaskResult{}
					jsonToTask(, &)
					.Tasks = append(.Tasks, .Task)
				}
			}
		}
	}

	,  := ["nextCursor"]
	if  {
		if ,  := .(string);  {
			.NextCursor = Cursor()
		}
	}

	return &, nil
}

// ParseTaskResultResult parses a JSON message and converts it to a TaskResultResult.
func ( *json.RawMessage) (*TaskResultResult, error) {
	if  == nil {
		return nil, fmt.Errorf("response is nil")
	}

	var  map[string]any
	if  := json.Unmarshal(*, &);  != nil {
		return nil, fmt.Errorf("failed to unmarshal response: %w", )
	}

	 := TaskResultResult{}
	,  := ["_meta"]
	if  {
		if ,  := .(map[string]any);  {
			.Meta = NewMetaFromMap()
		}
	}

	,  := ["result"]
	if  {
		if ,  := .(map[string]any);  {
			if ,  := ["isError"].(bool);  {
				.IsError = 
			}
			if ,  := ["content"].([]any);  {
				for ,  := range  {
					if ,  := .(map[string]any);  {
						,  := ParseContent()
						if  != nil {
							return nil, 
						}
						.Content = append(.Content, )
					}
				}
			}
		}
	}

	return &, nil
}

// ParseGetTaskResult parses a JSON message and converts it to a GetTaskResult.
func ( *json.RawMessage) (*GetTaskResult, error) {
	if  == nil {
		return nil, fmt.Errorf("response is nil")
	}

	var  map[string]any
	if  := json.Unmarshal(*, &);  != nil {
		return nil, fmt.Errorf("failed to unmarshal response: %w", )
	}

	 := GetTaskResult{}
	,  := ["_meta"]
	if  {
		if ,  := .(map[string]any);  {
			.Meta = NewMetaFromMap()
		}
	}

	jsonToTask(, &)

	return &, nil
}