package ansi

import (
	
	
)

// StatusReport represents a terminal status report.
type StatusReport interface {
	// StatusReport returns the status report identifier.
	StatusReport() int
}

// ANSIStatusReport represents an ANSI terminal status report.
type ANSIStatusReport int //nolint:revive

// StatusReport returns the status report identifier.
func ( ANSIStatusReport) () int {
	return int()
}

// DECStatusReport represents a DEC terminal status report.
type DECStatusReport int

// StatusReport returns the status report identifier.
func ( DECStatusReport) () int {
	return int()
}

// DeviceStatusReport (DSR) is a control sequence that reports the terminal's
// status.
// The terminal responds with a DSR sequence.
//
//	CSI Ps n
//	CSI ? Ps n
//
// If one of the statuses is a [DECStatus], the sequence will use the DEC
// format.
//
// See also https://vt100.net/docs/vt510-rm/DSR.html
func ( ...StatusReport) string {
	var  bool
	 := make([]string, len())
	 := "\x1b["
	for ,  := range  {
		[] = strconv.Itoa(.StatusReport())
		switch .(type) {
		case DECStatusReport:
			 = true
		}
	}
	if  {
		 += "?"
	}
	return  + strings.Join(, ";") + "n"
}

// DSR is an alias for [DeviceStatusReport].
func ( StatusReport) string {
	return DeviceStatusReport()
}

// RequestCursorPositionReport is an escape sequence that requests the current
// cursor position.
//
//	CSI 6 n
//
// The terminal will report the cursor position as a CSI sequence in the
// following format:
//
//	CSI Pl ; Pc R
//
// Where Pl is the line number and Pc is the column number.
// See: https://vt100.net/docs/vt510-rm/CPR.html
const RequestCursorPositionReport = "\x1b[6n"

// RequestExtendedCursorPositionReport (DECXCPR) is a sequence for requesting
// the cursor position report including the current page number.
//
//	CSI ? 6 n
//
// The terminal will report the cursor position as a CSI sequence in the
// following format:
//
//	CSI ? Pl ; Pc ; Pp R
//
// Where Pl is the line number, Pc is the column number, and Pp is the page
// number.
// See: https://vt100.net/docs/vt510-rm/DECXCPR.html
const RequestExtendedCursorPositionReport = "\x1b[?6n"

// RequestLightDarkReport is a control sequence that requests the terminal to
// report its operating system light/dark color preference. Supported terminals
// should respond with a [LightDarkReport] sequence as follows:
//
//	CSI ? 997 ; 1 n   for dark mode
//	CSI ? 997 ; 2 n   for light mode
//
// See: https://contour-terminal.org/vt-extensions/color-palette-update-notifications/
const RequestLightDarkReport = "\x1b[?996n"

// CursorPositionReport (CPR) is a control sequence that reports the cursor's
// position.
//
//	CSI Pl ; Pc R
//
// Where Pl is the line number and Pc is the column number.
//
// See also https://vt100.net/docs/vt510-rm/CPR.html
func (,  int) string {
	if  < 1 {
		 = 1
	}
	if  < 1 {
		 = 1
	}
	return "\x1b[" + strconv.Itoa() + ";" + strconv.Itoa() + "R"
}

// CPR is an alias for [CursorPositionReport].
func (,  int) string {
	return CursorPositionReport(, )
}

// ExtendedCursorPositionReport (DECXCPR) is a control sequence that reports the
// cursor's position along with the page number (optional).
//
//	CSI ? Pl ; Pc R
//	CSI ? Pl ; Pc ; Pv R
//
// Where Pl is the line number, Pc is the column number, and Pv is the page
// number.
//
// If the page number is zero or negative, the returned sequence won't include
// the page number.
//
// See also https://vt100.net/docs/vt510-rm/DECXCPR.html
func (, ,  int) string {
	if  < 1 {
		 = 1
	}
	if  < 1 {
		 = 1
	}
	if  < 1 {
		return "\x1b[?" + strconv.Itoa() + ";" + strconv.Itoa() + "R"
	}
	return "\x1b[?" + strconv.Itoa() + ";" + strconv.Itoa() + ";" + strconv.Itoa() + "R"
}

// DECXCPR is an alias for [ExtendedCursorPositionReport].
func (, ,  int) string {
	return ExtendedCursorPositionReport(, , )
}

// LightDarkReport is a control sequence that reports the terminal's operating
// system light/dark color preference.
//
//	CSI ? 997 ; 1 n   for dark mode
//	CSI ? 997 ; 2 n   for light mode
//
// See: https://contour-terminal.org/vt-extensions/color-palette-update-notifications/
func ( bool) string {
	if  {
		return "\x1b[?997;1n"
	}
	return "\x1b[?997;2n"
}