package ui

import (
	"github.com/unkn0wn-root/resterm/internal/engine"
	"github.com/unkn0wn-root/resterm/internal/engine/core"
	xplain "github.com/unkn0wn-root/resterm/internal/explain"
	"github.com/unkn0wn-root/resterm/internal/grpcclient"
	"github.com/unkn0wn-root/resterm/internal/httpclient"
	"github.com/unkn0wn-root/resterm/internal/restfile"
	"github.com/unkn0wn-root/resterm/internal/scripts"
	"github.com/unkn0wn-root/resterm/internal/stream"
	"github.com/unkn0wn-root/resterm/internal/update"
)

type statusPulseMsg struct {
	seq int
}

type tabSpinMsg struct {
	seq int
}

type latencyAnimMsg struct {
	seq int
}

type profileNextIterationMsg struct{}

type updateTickMsg struct{}

type statusLevel int

const (
	statusInfo statusLevel = iota
	statusWarn
	statusError
	statusSuccess
)

type responseMsg struct {
	response       *httpclient.Response
	grpc           *grpcclient.Response
	stream         *scripts.StreamInfo
	transcript     []byte
	err            error
	tests          []scripts.TestResult
	scriptErr      error
	executed       *restfile.Request
	requestText    string
	runtimeSecrets []string
	environment    string
	skipped        bool
	skipReason     string
	preview        bool
	explain        *xplain.Report
	historyDone    bool
}

type statusMsg struct {
	text  string
	level statusLevel
}

type updateCheckMsg struct {
	res *update.Result
	err error
}

type streamEventMsg struct {
	sessionID string
	events    []*stream.Event
}

type streamStateMsg struct {
	sessionID string
	state     stream.State
	err       error
}

type streamCompleteMsg struct {
	sessionID string
}

type streamReadyMsg struct {
	sessionID string
}

type wsConsoleResultMsg struct {
	err     error
	status  string
	mode    websocketConsoleMode
	payload string
}

type rawDumpLoadedMsg struct {
	snapshot *responseSnapshot
	mode     rawViewMode
	content  string
}

type externalEditorMsg struct {
	path string
	err  error
}

type runReqMsg struct {
	res engine.RequestResult
	err error
}

type runEvtMsg struct {
	evt core.Evt
}

type runWorkerDoneMsg struct {
	runID string
	err   error
}
