package constants

//------------------------------------------------
// Consultation waiting queue (astrologer_waiting_queue)
//------------------------------------------------
//
//	WAITING -> NOTIFIED -> CONNECTING -> CONNECTED -> COMPLETED
//	WAITING -> EXPIRED | CANCELLED
//	NOTIFIED -> EXPIRED | SKIPPED | CANCELLED | REJECTED
//	CONNECTING -> EXPIRED | REJECTED | CANCELLED
//
// Schema in migrations/2026_10_03_consultation_waiting_queue.sql.

const (
	QueueStatusWaiting    = "WAITING"
	QueueStatusNotified   = "NOTIFIED"
	QueueStatusConnecting = "CONNECTING"
	QueueStatusConnected  = "CONNECTED"
	QueueStatusExpired    = "EXPIRED"
	QueueStatusCancelled  = "CANCELLED"
	QueueStatusSkipped    = "SKIPPED"
	QueueStatusRejected   = "REJECTED"
	QueueStatusCompleted  = "COMPLETED"
)

// Why a queue row reached a terminal status (astrologer_waiting_queue.end_reason).
const (
	QueueEndWaitTimeout          = "WAIT_TIMEOUT"
	QueueEndNotifyTimeout        = "NOTIFY_TIMEOUT"
	QueueEndConnectTimeout       = "CONNECT_TIMEOUT"
	QueueEndCustomerCancelled    = "CUSTOMER_CANCELLED"
	QueueEndRemovedByAstrologer  = "REMOVED_BY_ASTROLOGER"
	QueueEndAstrologerUnavailable = "ASTROLOGER_UNAVAILABLE"
	QueueEndSessionOpenElsewhere = "SESSION_OPEN_ELSEWHERE"
	QueueEndInsufficientBalance  = "INSUFFICIENT_BALANCE"
	QueueEndRequestRejected      = "REQUEST_REJECTED"
	QueueEndRequestMissed        = "REQUEST_MISSED"
	QueueEndRequestCancelled     = "REQUEST_CANCELLED"
	QueueEndSessionCompleted     = "SESSION_COMPLETED"
)

// ActiveQueueStatuses hold a place in the queue.
func ActiveQueueStatuses() []string {
	return []string{QueueStatusWaiting, QueueStatusNotified, QueueStatusConnecting}
}

// IsActiveQueueStatus reports whether the row still holds a place in the queue.
func IsActiveQueueStatus(status string) bool {
	return status == QueueStatusWaiting ||
		status == QueueStatusNotified ||
		status == QueueStatusConnecting
}

// Admin panel > Settings > Consultation & Chat. The defaults in the services
// are only a fallback for a database without these rows.
const (
	FlagQueueMaxWaitingMinutes         = "QueueMaxWaitingMinutes"
	FlagQueueNotificationWindowSeconds = "QueueNotificationWindowSeconds"
	FlagQueueConnectionTimeoutSeconds  = "QueueConnectionTimeoutSeconds"

	// Active rows one astrologer's queue may hold, chat and call together.
	// 0 means unlimited.
	FlagQueueMaxCapacity = "QueueMaxCapacity"
)
