package main

type Config struct {
	Volcengine VolcengineConfig `toml:"volcengine"`
	Agent      AgentConfig      `toml:"agent"`
}

type VolcengineConfig struct {
	BaseURL string `toml:"base_url"`
	APIKey  string `toml:"api_key"`
	Model   string `toml:"model"`
}

type AgentConfig struct {
	AppDataDir         string `toml:"app_data_dir"`
	RegionsPath        string `toml:"regions_path"`
	ScreenshotPath     string `toml:"screenshot_path"`
	TaskOutputPath     string `toml:"task_output_path"`
	TaskHistoryDir     string `toml:"task_history_dir"`
	DryRun             bool   `toml:"dry_run"`
	ObserveMode        string `toml:"observe_mode"`
	MaxScrolls         int    `toml:"max_scrolls"`
	ScrollDeltaY       int    `toml:"scroll_delta_y"`
	ChatRecordsPath    string `toml:"chat_records_path"`
	ChatSyncMaxPages   int    `toml:"chat_sync_max_pages"`
	ChatSyncTopScrolls int    `toml:"chat_sync_top_scrolls"`
}

type WindowBounds struct {
	X      float64
	Y      float64
	Width  float64
	Height float64
	Owner  string
	Title  string
	ID     int
}

type LogEntry struct {
	Level     string `json:"level"`
	Message   string `json:"message"`
	Timestamp string `json:"timestamp"`
}

type AnnotationFile struct {
	App              string          `json:"app"`
	ScreenshotPath   string          `json:"screenshotPath"`
	ScreenshotWidth  int             `json:"screenshotWidth"`
	ScreenshotHeight int             `json:"screenshotHeight"`
	ScaleFactor      float64         `json:"scaleFactor"`
	Source           jsonRawOptional `json:"source,omitempty"`
	Regions          []Region        `json:"regions"`
	CreatedAt        string          `json:"createdAt"`
	UpdatedAt        string          `json:"updatedAt"`
}

type jsonRawOptional map[string]any

type Region struct {
	ID          string     `json:"id"`
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Type        string     `json:"type"`
	BBoxImage   [4]float64 `json:"bbox_image"`
	BBoxSource  [4]float64 `json:"bbox_source,omitempty"`
	BBoxScreen  [4]float64 `json:"bbox_screen"`
	ScaleFactor float64    `json:"scaleFactor"`
}

type RegionSummary struct {
	Name         string     `json:"name"`
	Description  string     `json:"description,omitempty"`
	Type         string     `json:"type"`
	BBoxScreen   [4]float64 `json:"bbox_screen"`
	BBoxSource   [4]float64 `json:"bbox_source,omitempty"`
	CenterScreen [2]float64 `json:"center_screen"`
	CenterSource [2]float64 `json:"center_source,omitempty"`
}

type Task struct {
	TaskID       string          `json:"task_id"`
	TaskName     string          `json:"task_name"`
	TaskType     string          `json:"task_type"`
	TaskStatus   string          `json:"task_status"`
	CreatedAt    string          `json:"created_at"`
	Source       TaskSource      `json:"source"`
	Confidence   float64         `json:"confidence"`
	LLMSummary   LLMSummary      `json:"llm_summary"`
	Regions      []RegionSummary `json:"regions"`
	Actions      []Action        `json:"actions"`
	ExecutionLog []ExecutionLog  `json:"execution_log"`
}

type TaskSource struct {
	RegionsPath    string `json:"regions_path"`
	ScreenshotPath string `json:"screenshot_path"`
}

type LLMSummary struct {
	ContactName       string `json:"contact_name"`
	ChatSummary       string `json:"chat_summary"`
	LatestUserMessage string `json:"latest_user_message"`
	ReplyText         string `json:"reply_text"`
}

type Action struct {
	ActionID     string      `json:"action_id"`
	Type         string      `json:"type"`
	Name         string      `json:"name"`
	Status       string      `json:"status"`
	TargetRegion string      `json:"target_region,omitempty"`
	Point        *[2]float64 `json:"point,omitempty"`
	Text         string      `json:"text,omitempty"`
	DeltaY       int         `json:"delta_y,omitempty"`
	DurationMs   int         `json:"duration_ms,omitempty"`
	Reason       string      `json:"reason,omitempty"`
}

type ExecutionLog struct {
	ActionID string `json:"action_id"`
	Status   string `json:"status"`
	Message  string `json:"message"`
	Time     string `json:"time"`
}

type openAIRequest struct {
	Model       string          `json:"model"`
	Messages    []openAIMessage `json:"messages"`
	Temperature float64         `json:"temperature"`
}

type openAIMessage struct {
	Role    string          `json:"role"`
	Content []openAIContent `json:"content"`
}

type openAIContent struct {
	Type     string          `json:"type"`
	Text     string          `json:"text,omitempty"`
	ImageURL *openAIImageURL `json:"image_url,omitempty"`
}

type openAIImageURL struct {
	URL string `json:"url"`
}

type openAIResponse struct {
	Choices []struct {
		Message struct {
			Content string `json:"content"`
		} `json:"message"`
	} `json:"choices"`
	Error *struct {
		Message string `json:"message"`
	} `json:"error,omitempty"`
}

type ChatArchive struct {
	App       string        `json:"app"`
	Contact   string        `json:"contact"`
	Source    TaskSource    `json:"source"`
	Messages  []ChatMessage `json:"messages"`
	Pages     []ChatPage    `json:"pages"`
	CreatedAt string        `json:"created_at"`
	UpdatedAt string        `json:"updated_at"`
}

type ChatMessage struct {
	ID        string `json:"id"`
	Sender    string `json:"sender"`
	Role      string `json:"role"`
	Time      string `json:"time,omitempty"`
	Content   string `json:"content"`
	PageIndex int    `json:"page_index"`
	SeenAt    string `json:"seen_at"`
}

type ChatPage struct {
	PageIndex int    `json:"page_index"`
	Direction string `json:"direction"`
	NewCount  int    `json:"new_count"`
	SeenAt    string `json:"seen_at"`
}

type ChatExtractResult struct {
	ContactName string        `json:"contact_name"`
	PageSummary string        `json:"page_summary"`
	Messages    []ChatMessage `json:"messages"`
}
