package workspaceprotocol

import (
	iop "iop/proto/gen/iop"
)

// ToolTerminal returns the exact canonical message for a tool status and error code pair.
// Returns (message, true) for valid canonical pairs, or ("", false) if the pair is invalid.
func ToolTerminal(status iop.WorkspaceStatus, code iop.WorkspaceErrorCode) (string, bool) {
	switch {
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_SUCCESS && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_UNSPECIFIED:
		return "", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_READY:
		return "workspace runtime not ready", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_UNSUPPORTED:
		return "workspace operation unsupported", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_FOUND:
		return "workspace entry not found", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INVALID_REQUEST:
		return "workspace request rejected", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_TIMEOUT && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_TIMEOUT:
		return "workspace command timed out", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_CANCELLED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_CANCELLED:
		return "workspace command cancelled", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INTERNAL:
		return "workspace operation failed", true
	default:
		return "", false
	}
}

// ArtifactTerminal returns the exact canonical message for an internal artifact
// status and error code pair. Artifact terminals never include a path, artifact
// content, or a raw filesystem/runtime error.
func ArtifactTerminal(status iop.WorkspaceStatus, code iop.WorkspaceErrorCode) (string, bool) {
	switch {
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_SUCCESS && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_UNSPECIFIED:
		return "", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_READY:
		return "workspace runtime not ready", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_FOUND:
		return "workspace artifact not found", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INVALID_REQUEST:
		return "workspace artifact request rejected", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INTERNAL:
		return "workspace artifact operation failed", true
	default:
		return "", false
	}
}

// CancelTerminal returns the exact canonical message for a cancel status and error code pair.
// Returns (message, true) for valid canonical pairs, or ("", false) if the pair is invalid.
func CancelTerminal(status iop.WorkspaceStatus, code iop.WorkspaceErrorCode) (string, bool) {
	switch {
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_CANCELLED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_CANCELLED:
		return "workspace command cancelled", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_FOUND:
		return "workspace command not found", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INVALID_REQUEST:
		return "workspace cancellation rejected", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_READY:
		return "workspace runtime not ready", true
	default:
		return "", false
	}
}

// OpenTerminal returns the exact canonical message for an open status and error code pair.
// Returns (message, true) for valid canonical pairs, or ("", false) if the pair is invalid.
func OpenTerminal(status iop.WorkspaceStatus, code iop.WorkspaceErrorCode) (string, bool) {
	switch {
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_SUCCESS && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_UNSPECIFIED:
		return "", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_READY:
		return "workspace runtime not ready", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INVALID_REQUEST:
		return "workspace open rejected", true
	default:
		return "", false
	}
}

// CleanupTerminal returns the exact canonical message for a cleanup status and error code pair.
// Returns (message, true) for valid canonical pairs, or ("", false) if the pair is invalid.
func CleanupTerminal(status iop.WorkspaceStatus, code iop.WorkspaceErrorCode) (string, bool) {
	switch {
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_SUCCESS && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_UNSPECIFIED:
		return "", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_READY:
		return "workspace runtime not ready", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_UNSUPPORTED:
		return "workspace cleanup unsupported", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_NOT_FOUND:
		return "workspace request not found", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INVALID_REQUEST:
		return "workspace cleanup rejected", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_TIMEOUT && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_TIMEOUT:
		return "workspace cleanup timed out", true
	case status == iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR && code == iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INTERNAL:
		return "workspace cleanup failed", true
	default:
		return "", false
	}
}
