package errors

// APIError is the unified error payload returned by HTTP handlers.
// It follows the PDF convention with code/message and optional details.
type APIError struct {
	Code      string      `json:"code"`
	Message   string      `json:"message"`
	RequestID string      `json:"requestId,omitempty"`
	Details   interface{} `json:"details,omitempty"`
}

// UnknownFieldDetails is returned when a single SQL query references fields
// that the selected query engine cannot resolve.
type UnknownFieldDetails struct {
	Reason    string   `json:"reason" example:"UNKNOWN_FIELD"`
	Fields    []string `json:"fields"`
	Retryable bool     `json:"retryable" example:"false"`
}

// UnknownFieldBatchQuery identifies one failed item in an all-or-nothing SQL batch.
type UnknownFieldBatchQuery struct {
	Index  int      `json:"index" example:"0"`
	Fields []string `json:"fields"`
}

// UnknownFieldBatchDetails is returned when all failures in a SQL batch are
// safely classified as unresolved fields.
type UnknownFieldBatchDetails struct {
	Reason    string                   `json:"reason" example:"UNKNOWN_FIELD"`
	Retryable bool                     `json:"retryable" example:"false"`
	Queries   []UnknownFieldBatchQuery `json:"queries"`
}

func NewBadRequestErr(message string) *APIError {
	return &APIError{
		Code:    "InvalidArgument",
		Message: message,
	}
}

func NewInternalErr(message string) *APIError {
	return &APIError{
		Code:    "InternalError",
		Message: message,
	}
}
