sylphx 0.3.2

The Sylphx SDK: one API, one key, every Sylphx service. Generated from the Sylphx schema registry.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
// @generated by sylphx-gen 0.1.0 from contracts@c8a7361c53e572321b0ec9fb014fd1e8279b007b62562423038e0d0e5b9d767a. Do not edit.
//! `sylphx.common.v1`.

#![allow(clippy::all)]

/// Condition is one observation a controller makes about a Resource
/// (kstatus: `Ready`, `Reconciling`, `Stalled`). A Resource is settled when
/// `status.observed_generation == meta.generation` and `Reconciling` is not
/// TRUE; it is healthy when settled and `Ready` is TRUE.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct Condition {
    /// The condition type, for example `Ready`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub r#type: String,
    /// Whether the condition holds.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub status: Option<ConditionStatus>,
    /// The generation this observation was made against.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        with = "crate::runtime::int64",
        alias = "observedGeneration"
    )]
    pub observed_generation: i64,
    /// A machine-readable UpperCamelCase reason.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub reason: String,
    /// A customer-safe human-readable message.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub message: String,
    /// How severe a FALSE condition is.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub severity: Option<Severity>,
    /// When `status` last changed.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "transitionTime"
    )]
    pub transition_time: String,
}

/// EntitlementDenial is the detail of `PLAN_LIMIT_REACHED` and
/// `SPEND_LIMIT_REACHED` (metering.md §9.3).
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct EntitlementDenial {
    /// The meter that hit its limit.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub meter: String,
    /// The limit in the meter's unit.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        with = "crate::runtime::int64"
    )]
    pub limit: i64,
    /// The org's plan.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub plan: String,
    /// Where the org can raise the limit.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "upgradeUrl"
    )]
    pub upgrade_url: String,
}

/// Operation is the wire shape of a long-running operation
/// (resource-api-and-clients.md §3.9, AIP-151).
///
/// In the schema, a long-running method returns `google.longrunning.Operation`
/// with `google.longrunning.operation_info`, so the AIP linter can check it;
/// on the wire, and in every generated client, that return type is this
/// message. An Operation of a reconciled Resource is a view, not a second
/// state machine: it is `done` when the target's `observed_generation` reaches
/// `target_generation` and `Reconciling` is not TRUE.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct Operation {
    /// `{parent-of-target}/operations/{operation}`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub name: String,
    /// The name of the Resource being changed.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub target: String,
    /// The generation this Operation waits for.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        with = "crate::runtime::int64",
        alias = "targetGeneration"
    )]
    pub target_generation: i64,
    /// What the Operation does.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub verb: Option<OperationVerb>,
    /// The custom method verb when `verb` is CUSTOM, for example `revoke`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "customVerb"
    )]
    pub custom_verb: String,
    /// Whether the Operation has finished.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub done: bool,
    /// When the Operation started.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "createTime"
    )]
    pub create_time: String,
    /// When the Operation finished.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "endTime"
    )]
    pub end_time: String,
    /// The settled Resource (or Empty for a delete).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub response: Option<serde_json::Value>,
    /// The failure, as the one error body.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<ProblemDetails>,
    /// Progress while not `done`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub progress: Option<OperationProgress>,
}

/// OperationProgress is the progress of an Operation that is not done. It is
/// also the `metadata_type` of every long-running method.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct OperationProgress {
    /// Percent complete, when the controller can tell.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub percent: Option<i32>,
    /// A customer-safe progress message.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub message: String,
    /// The target's conditions when this progress was read.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub conditions: Vec<Condition>,
}

/// PreconditionFailure is the detail of `ETAG_MISMATCH`.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct PreconditionFailure {
    /// The Resource's current etag, so the client can re-read and retry.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "currentEtag"
    )]
    pub current_etag: String,
}

/// ProblemDetails is the one error body of every method and service
/// (resource-api-and-clients.md §3.8): RFC 9457 problem details served as
/// `application/problem+json`.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ProblemDetails {
    /// `https://sylphx.com/docs/errors/<code in kebab-case>`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub r#type: String,
    /// A short customer-safe summary of the problem class.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub title: String,
    /// The HTTP status, fixed by `grpc_status`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub status: i32,
    /// A customer-safe explanation of this occurrence. Never contains SQL, stack
    /// traces, internal hostnames, or another tenant's data.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub detail: String,
    /// The request id (`Sylphx-Request-Id`).
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub instance: String,
    /// The stable UPPER_SNAKE code, one of ErrorCode without its prefix.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub code: String,
    /// One of the 16 canonical gRPC status names, for example `ABORTED`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "grpcStatus"
    )]
    pub grpc_status: String,
    /// Whether the same request may be retried.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub retryable: bool,
    /// What the failed call committed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub effect: Option<ErrorEffect>,
    /// How long to wait before retrying, when the server knows.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        with = "crate::runtime::opt_int64",
        alias = "retryAfterMs"
    )]
    pub retry_after_ms: Option<i64>,
    /// Typed details such as PreconditionFailure or EntitlementDenial.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub details: Vec<serde_json::Value>,
}

/// ResourceMeta is the metadata every Resource carries in field 3.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ResourceMeta {
    /// Increases by one on every change to `spec`.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        with = "crate::runtime::int64"
    )]
    pub generation: i64,
    /// Strong ETag (AIP-154): changes on any change to spec, status, or
    /// metadata. Send it back as `If-Match` or `etag` to make Update and Delete
    /// conditional; a mismatch fails with ABORTED / 409 `ETAG_MISMATCH`.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub etag: String,
    /// When the Resource was created.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "createTime"
    )]
    pub create_time: String,
    /// When the Resource last changed.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "updateTime"
    )]
    pub update_time: String,
    /// Set while the Resource is being deleted.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "deleteTime"
    )]
    pub delete_time: String,
    /// Caller-writable, indexed labels (AIP-122 label rules).
    #[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
    pub labels: std::collections::BTreeMap<String, String>,
    /// Caller-writable, unindexed annotations.
    #[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
    pub annotations: std::collections::BTreeMap<String, String>,
    /// Caller-writable human-readable name.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "displayName"
    )]
    pub display_name: String,
    /// The principal that created the Resource.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub creator: String,
}

/// ConditionStatus is the truth value of a Condition.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ConditionStatus {
    /// The condition holds.
    True,
    /// The condition does not hold.
    False,
    /// The controller cannot tell.
    UnknownValue,
    /// A value this SDK version does not know.
    Unknown(String),
}

impl ConditionStatus {
    /// The wire string.
    pub fn as_str(&self) -> &str {
        match self {
            Self::True => "true",
            Self::False => "false",
            Self::UnknownValue => "unknown",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Parses a wire string; unknown values are kept.
    pub fn from_wire(s: &str) -> Self {
        match s {
            "true" => Self::True,
            "false" => Self::False,
            "unknown" => Self::UnknownValue,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl serde::Serialize for ConditionStatus {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> serde::Deserialize<'de> for ConditionStatus {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        let s = <String as serde::Deserialize>::deserialize(d)?;
        Ok(Self::from_wire(&s))
    }
}

impl crate::runtime::QueryValue for ConditionStatus {
    fn query_value(&self) -> Option<String> {
        Some(self.as_str().to_string())
    }
}

/// ErrorCode is the registry of error codes (§6.3 rule 5). A method lists the
/// codes it may return in `(sylphx.common.v1.method).errors`, without the
/// `ERROR_CODE_` prefix. Adding a code is additive; removing one is breaking.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ErrorCode {
    /// INVALID_ARGUMENT: the request has a field the schema does not know.
    UnknownField,
    /// INVALID_ARGUMENT: a field failed validation.
    InvalidField,
    /// INVALID_ARGUMENT: a page token was reused with different parameters.
    PageTokenMismatch,
    /// INVALID_ARGUMENT / 422: an Idempotency-Key was reused with another body.
    IdempotencyKeyReused,
    /// ABORTED: the first call with this Idempotency-Key is still running.
    IdempotencyInProgress,
    /// ABORTED: the etag sent does not match the Resource's current etag.
    EtagMismatch,
    /// NOT_FOUND: the named Resource does not exist or is not visible.
    ResourceNotFound,
    /// ALREADY_EXISTS: a Resource with this name exists.
    ResourceAlreadyExists,
    /// UNAUTHENTICATED: no valid key or token was presented.
    Unauthenticated,
    /// PERMISSION_DENIED: the key lacks the method's permission.
    PermissionDenied,
    /// FAILED_PRECONDITION: `spec.deletion_protection` blocks the delete.
    DeletionProtected,
    /// FAILED_PRECONDITION: the controller reported Stalled or Ready=FALSE.
    ReconcileFailed,
    /// FAILED_PRECONDITION / 402: the plan's limit is reached.
    PlanLimitReached,
    /// FAILED_PRECONDITION / 402: the org's spend limit is reached.
    SpendLimitReached,
    /// RESOURCE_EXHAUSTED: the rate limit is reached; see Retry-After.
    RateLimited,
    /// FAILED_PRECONDITION: the Resource is in a state that forbids the call.
    InvalidState,
    /// INTERNAL: an internal fault; the cause is in Observability by request id.
    Internal,
    /// UNAVAILABLE: the Resource store, the owning service's backend, or the
    /// key verifier's snapshot is unavailable; retry after Retry-After.
    Unavailable,
    /// UNIMPLEMENTED: the path or method is not served (yet) at this version.
    Unimplemented,
    /// UNAUTHENTICATED / 401: a key created seconds ago has not reached the
    /// cell serving this request yet; retry within `active_after_ms`.
    NotYetPropagated,
    /// DEADLINE_EXCEEDED: the client deadline passed before the work committed.
    DeadlineExceeded,
    /// NOT_FOUND: no method is served at this path.
    NotFound,
    /// UNAVAILABLE: the backend serves another contract image than the API
    /// endpoint for this service; the Release rolls them in order.
    ContractSkew,
    /// UNAVAILABLE / 503: no machine can be granted now (immediate-or-fail);
    /// retry after Retry-After.
    NoCapacity,
    /// FAILED_PRECONDITION / 422: the requested shape or kind is not sold.
    ShapeNotOffered,
    /// ABORTED / 409: the call named a lease generation or control epoch that is
    /// no longer current.
    StaleGeneration,
    /// FAILED_PRECONDITION / 409: the Resource is attached to or held by another
    /// Resource, for example a volume attached to a running lease.
    ResourceInUse,
    /// FAILED_PRECONDITION / 409: another holder has input control of the
    /// display.
    ControlHeld,
    /// FAILED_PRECONDITION / 409: a human has taken over the display; agent input
    /// and screenshots are refused until control is released or expires.
    ControlHeldByHuman,
    /// INVALID_ARGUMENT: a name segment is not a current id, and no id map row
    /// moves it (identifiers-convergence.md §4.4).
    InvalidId,
    /// INVALID_ARGUMENT: the `If-Match` header and the request's `etag` name
    /// different etags; send one, or the same.
    EtagConflict,
    /// INVALID_ARGUMENT: the method has no dry run; a request with
    /// `validate_only` is refused before anything is written.
    ValidateOnlyNotSupported,
    /// 308 on GET/HEAD: the id in the name moved in the identifiers cut;
    /// `Location` and `Sylphx-Moved-To` carry the new one, and the body is
    /// `{"error":"id_moved","old":…,"new":…}`, for the 14-day window of the
    /// owning service (identifiers-convergence.md §4.4). The Resource-API
    /// moved-id resolver answers it in front of every service.
    IdMoved,
    /// A value this SDK version does not know.
    Unknown(String),
}

impl ErrorCode {
    /// The wire string.
    pub fn as_str(&self) -> &str {
        match self {
            Self::UnknownField => "UNKNOWN_FIELD",
            Self::InvalidField => "INVALID_FIELD",
            Self::PageTokenMismatch => "PAGE_TOKEN_MISMATCH",
            Self::IdempotencyKeyReused => "IDEMPOTENCY_KEY_REUSED",
            Self::IdempotencyInProgress => "IDEMPOTENCY_IN_PROGRESS",
            Self::EtagMismatch => "ETAG_MISMATCH",
            Self::ResourceNotFound => "RESOURCE_NOT_FOUND",
            Self::ResourceAlreadyExists => "RESOURCE_ALREADY_EXISTS",
            Self::Unauthenticated => "UNAUTHENTICATED",
            Self::PermissionDenied => "PERMISSION_DENIED",
            Self::DeletionProtected => "DELETION_PROTECTED",
            Self::ReconcileFailed => "RECONCILE_FAILED",
            Self::PlanLimitReached => "PLAN_LIMIT_REACHED",
            Self::SpendLimitReached => "SPEND_LIMIT_REACHED",
            Self::RateLimited => "RATE_LIMITED",
            Self::InvalidState => "INVALID_STATE",
            Self::Internal => "INTERNAL",
            Self::Unavailable => "UNAVAILABLE",
            Self::Unimplemented => "UNIMPLEMENTED",
            Self::NotYetPropagated => "NOT_YET_PROPAGATED",
            Self::DeadlineExceeded => "DEADLINE_EXCEEDED",
            Self::NotFound => "NOT_FOUND",
            Self::ContractSkew => "CONTRACT_SKEW",
            Self::NoCapacity => "NO_CAPACITY",
            Self::ShapeNotOffered => "SHAPE_NOT_OFFERED",
            Self::StaleGeneration => "STALE_GENERATION",
            Self::ResourceInUse => "RESOURCE_IN_USE",
            Self::ControlHeld => "CONTROL_HELD",
            Self::ControlHeldByHuman => "CONTROL_HELD_BY_HUMAN",
            Self::InvalidId => "INVALID_ID",
            Self::EtagConflict => "ETAG_CONFLICT",
            Self::ValidateOnlyNotSupported => "VALIDATE_ONLY_NOT_SUPPORTED",
            Self::IdMoved => "ID_MOVED",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Parses a wire string; unknown values are kept.
    pub fn from_wire(s: &str) -> Self {
        match s {
            "UNKNOWN_FIELD" => Self::UnknownField,
            "INVALID_FIELD" => Self::InvalidField,
            "PAGE_TOKEN_MISMATCH" => Self::PageTokenMismatch,
            "IDEMPOTENCY_KEY_REUSED" => Self::IdempotencyKeyReused,
            "IDEMPOTENCY_IN_PROGRESS" => Self::IdempotencyInProgress,
            "ETAG_MISMATCH" => Self::EtagMismatch,
            "RESOURCE_NOT_FOUND" => Self::ResourceNotFound,
            "RESOURCE_ALREADY_EXISTS" => Self::ResourceAlreadyExists,
            "UNAUTHENTICATED" => Self::Unauthenticated,
            "PERMISSION_DENIED" => Self::PermissionDenied,
            "DELETION_PROTECTED" => Self::DeletionProtected,
            "RECONCILE_FAILED" => Self::ReconcileFailed,
            "PLAN_LIMIT_REACHED" => Self::PlanLimitReached,
            "SPEND_LIMIT_REACHED" => Self::SpendLimitReached,
            "RATE_LIMITED" => Self::RateLimited,
            "INVALID_STATE" => Self::InvalidState,
            "INTERNAL" => Self::Internal,
            "UNAVAILABLE" => Self::Unavailable,
            "UNIMPLEMENTED" => Self::Unimplemented,
            "NOT_YET_PROPAGATED" => Self::NotYetPropagated,
            "DEADLINE_EXCEEDED" => Self::DeadlineExceeded,
            "NOT_FOUND" => Self::NotFound,
            "CONTRACT_SKEW" => Self::ContractSkew,
            "NO_CAPACITY" => Self::NoCapacity,
            "SHAPE_NOT_OFFERED" => Self::ShapeNotOffered,
            "STALE_GENERATION" => Self::StaleGeneration,
            "RESOURCE_IN_USE" => Self::ResourceInUse,
            "CONTROL_HELD" => Self::ControlHeld,
            "CONTROL_HELD_BY_HUMAN" => Self::ControlHeldByHuman,
            "INVALID_ID" => Self::InvalidId,
            "ETAG_CONFLICT" => Self::EtagConflict,
            "VALIDATE_ONLY_NOT_SUPPORTED" => Self::ValidateOnlyNotSupported,
            "ID_MOVED" => Self::IdMoved,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl serde::Serialize for ErrorCode {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> serde::Deserialize<'de> for ErrorCode {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        let s = <String as serde::Deserialize>::deserialize(d)?;
        Ok(Self::from_wire(&s))
    }
}

impl crate::runtime::QueryValue for ErrorCode {
    fn query_value(&self) -> Option<String> {
        Some(self.as_str().to_string())
    }
}

/// ErrorEffect says what a failed call committed (standards/dx.md "retry and
/// effect status").
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ErrorEffect {
    /// Nothing was committed.
    None,
    /// The write was committed, for example an Operation whose wait timed out.
    Applied,
    /// Re-read before retrying without an idempotency key.
    UnknownValue,
    /// A value this SDK version does not know.
    Unknown(String),
}

impl ErrorEffect {
    /// The wire string.
    pub fn as_str(&self) -> &str {
        match self {
            Self::None => "none",
            Self::Applied => "applied",
            Self::UnknownValue => "unknown",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Parses a wire string; unknown values are kept.
    pub fn from_wire(s: &str) -> Self {
        match s {
            "none" => Self::None,
            "applied" => Self::Applied,
            "unknown" => Self::UnknownValue,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl serde::Serialize for ErrorEffect {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> serde::Deserialize<'de> for ErrorEffect {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        let s = <String as serde::Deserialize>::deserialize(d)?;
        Ok(Self::from_wire(&s))
    }
}

impl crate::runtime::QueryValue for ErrorEffect {
    fn query_value(&self) -> Option<String> {
        Some(self.as_str().to_string())
    }
}

/// OperationVerb is the kind of change an Operation carries.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum OperationVerb {
    /// A Create.
    Create,
    /// An Update.
    Update,
    /// A Delete.
    Delete,
    /// A custom method; see `custom_verb`.
    Custom,
    /// A value this SDK version does not know.
    Unknown(String),
}

impl OperationVerb {
    /// The wire string.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Create => "create",
            Self::Update => "update",
            Self::Delete => "delete",
            Self::Custom => "custom",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Parses a wire string; unknown values are kept.
    pub fn from_wire(s: &str) -> Self {
        match s {
            "create" => Self::Create,
            "update" => Self::Update,
            "delete" => Self::Delete,
            "custom" => Self::Custom,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl serde::Serialize for OperationVerb {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> serde::Deserialize<'de> for OperationVerb {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        let s = <String as serde::Deserialize>::deserialize(d)?;
        Ok(Self::from_wire(&s))
    }
}

impl crate::runtime::QueryValue for OperationVerb {
    fn query_value(&self) -> Option<String> {
        Some(self.as_str().to_string())
    }
}

/// Severity grades a Condition that does not hold.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Severity {
    /// Informational.
    Info,
    /// Degraded but serving.
    Warning,
    /// Failed; an Operation waiting on this Resource ends with RECONCILE_FAILED.
    Error,
    /// A value this SDK version does not know.
    Unknown(String),
}

impl Severity {
    /// The wire string.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Info => "info",
            Self::Warning => "warning",
            Self::Error => "error",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Parses a wire string; unknown values are kept.
    pub fn from_wire(s: &str) -> Self {
        match s {
            "info" => Self::Info,
            "warning" => Self::Warning,
            "error" => Self::Error,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl serde::Serialize for Severity {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> serde::Deserialize<'de> for Severity {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        let s = <String as serde::Deserialize>::deserialize(d)?;
        Ok(Self::from_wire(&s))
    }
}

impl crate::runtime::QueryValue for Severity {
    fn query_value(&self) -> Option<String> {
        Some(self.as_str().to_string())
    }
}