Skip to main content

yauth_entity/diesel/
models.rs

1use chrono::NaiveDateTime;
2use diesel::prelude::*;
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6use super::schema::*;
7
8// ──────────────────────────────────────────────
9// Core: yauth_users
10// ──────────────────────────────────────────────
11
12#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
13#[diesel(table_name = yauth_users)]
14#[diesel(check_for_backend(diesel::pg::Pg))]
15pub struct User {
16    pub id: Uuid,
17    pub email: String,
18    pub display_name: Option<String>,
19    pub email_verified: bool,
20    pub role: String,
21    pub banned: bool,
22    pub banned_reason: Option<String>,
23    pub banned_until: Option<NaiveDateTime>,
24    pub created_at: NaiveDateTime,
25    pub updated_at: NaiveDateTime,
26}
27
28#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
29#[diesel(table_name = yauth_users)]
30pub struct NewUser {
31    pub id: Uuid,
32    pub email: String,
33    pub display_name: Option<String>,
34    pub email_verified: bool,
35    pub role: String,
36    pub banned: bool,
37    pub banned_reason: Option<String>,
38    pub banned_until: Option<NaiveDateTime>,
39    pub created_at: NaiveDateTime,
40    pub updated_at: NaiveDateTime,
41}
42
43#[derive(Debug, Clone, AsChangeset, Serialize, Deserialize)]
44#[diesel(table_name = yauth_users)]
45pub struct UpdateUser {
46    pub email: Option<String>,
47    pub display_name: Option<Option<String>>,
48    pub email_verified: Option<bool>,
49    pub role: Option<String>,
50    pub banned: Option<bool>,
51    pub banned_reason: Option<Option<String>>,
52    pub banned_until: Option<Option<NaiveDateTime>>,
53    pub updated_at: Option<NaiveDateTime>,
54}
55
56// ──────────────────────────────────────────────
57// Core: yauth_sessions
58// ──────────────────────────────────────────────
59
60#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
61#[diesel(table_name = yauth_sessions)]
62#[diesel(check_for_backend(diesel::pg::Pg))]
63pub struct Session {
64    pub id: Uuid,
65    pub user_id: Uuid,
66    pub token_hash: String,
67    pub ip_address: Option<String>,
68    pub user_agent: Option<String>,
69    pub expires_at: NaiveDateTime,
70    pub created_at: NaiveDateTime,
71}
72
73#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
74#[diesel(table_name = yauth_sessions)]
75pub struct NewSession {
76    pub id: Uuid,
77    pub user_id: Uuid,
78    pub token_hash: String,
79    pub ip_address: Option<String>,
80    pub user_agent: Option<String>,
81    pub expires_at: NaiveDateTime,
82    pub created_at: NaiveDateTime,
83}
84
85// ──────────────────────────────────────────────
86// Core: yauth_audit_log
87// ──────────────────────────────────────────────
88
89#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
90#[diesel(table_name = yauth_audit_log)]
91#[diesel(check_for_backend(diesel::pg::Pg))]
92pub struct AuditLog {
93    pub id: Uuid,
94    pub user_id: Option<Uuid>,
95    pub event_type: String,
96    pub metadata: Option<serde_json::Value>,
97    pub ip_address: Option<String>,
98    pub created_at: NaiveDateTime,
99}
100
101#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
102#[diesel(table_name = yauth_audit_log)]
103pub struct NewAuditLog {
104    pub id: Uuid,
105    pub user_id: Option<Uuid>,
106    pub event_type: String,
107    pub metadata: Option<serde_json::Value>,
108    pub ip_address: Option<String>,
109    pub created_at: NaiveDateTime,
110}
111
112// ──────────────────────────────────────────────
113// email-password: yauth_passwords
114// ──────────────────────────────────────────────
115
116#[cfg(feature = "email-password")]
117#[derive(Debug, Clone, Queryable, Selectable, Insertable, Serialize, Deserialize)]
118#[diesel(table_name = yauth_passwords)]
119#[diesel(check_for_backend(diesel::pg::Pg))]
120pub struct Password {
121    pub user_id: Uuid,
122    pub password_hash: String,
123}
124
125#[cfg(feature = "email-password")]
126#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
127#[diesel(table_name = yauth_passwords)]
128pub struct NewPassword {
129    pub user_id: Uuid,
130    pub password_hash: String,
131}
132
133#[cfg(feature = "email-password")]
134#[derive(Debug, Clone, AsChangeset, Serialize, Deserialize)]
135#[diesel(table_name = yauth_passwords)]
136pub struct UpdatePassword {
137    pub password_hash: Option<String>,
138}
139
140// ──────────────────────────────────────────────
141// email-password: yauth_email_verifications
142// ──────────────────────────────────────────────
143
144#[cfg(feature = "email-password")]
145#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
146#[diesel(table_name = yauth_email_verifications)]
147#[diesel(check_for_backend(diesel::pg::Pg))]
148pub struct EmailVerification {
149    pub id: Uuid,
150    pub user_id: Uuid,
151    pub token_hash: String,
152    pub expires_at: NaiveDateTime,
153    pub created_at: NaiveDateTime,
154}
155
156#[cfg(feature = "email-password")]
157#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
158#[diesel(table_name = yauth_email_verifications)]
159pub struct NewEmailVerification {
160    pub id: Uuid,
161    pub user_id: Uuid,
162    pub token_hash: String,
163    pub expires_at: NaiveDateTime,
164    pub created_at: NaiveDateTime,
165}
166
167// ──────────────────────────────────────────────
168// email-password: yauth_password_resets
169// ──────────────────────────────────────────────
170
171#[cfg(feature = "email-password")]
172#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
173#[diesel(table_name = yauth_password_resets)]
174#[diesel(check_for_backend(diesel::pg::Pg))]
175pub struct PasswordReset {
176    pub id: Uuid,
177    pub user_id: Uuid,
178    pub token_hash: String,
179    pub expires_at: NaiveDateTime,
180    pub used_at: Option<NaiveDateTime>,
181    pub created_at: NaiveDateTime,
182}
183
184#[cfg(feature = "email-password")]
185#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
186#[diesel(table_name = yauth_password_resets)]
187pub struct NewPasswordReset {
188    pub id: Uuid,
189    pub user_id: Uuid,
190    pub token_hash: String,
191    pub expires_at: NaiveDateTime,
192    pub created_at: NaiveDateTime,
193}
194
195// ──────────────────────────────────────────────
196// passkey: yauth_webauthn_credentials
197// ──────────────────────────────────────────────
198
199#[cfg(feature = "passkey")]
200#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
201#[diesel(table_name = yauth_webauthn_credentials)]
202#[diesel(check_for_backend(diesel::pg::Pg))]
203pub struct WebauthnCredential {
204    pub id: Uuid,
205    pub user_id: Uuid,
206    pub name: String,
207    pub aaguid: Option<String>,
208    pub device_name: Option<String>,
209    pub credential: serde_json::Value,
210    pub created_at: NaiveDateTime,
211    pub last_used_at: Option<NaiveDateTime>,
212}
213
214#[cfg(feature = "passkey")]
215#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
216#[diesel(table_name = yauth_webauthn_credentials)]
217pub struct NewWebauthnCredential {
218    pub id: Uuid,
219    pub user_id: Uuid,
220    pub name: String,
221    pub aaguid: Option<String>,
222    pub device_name: Option<String>,
223    pub credential: serde_json::Value,
224    pub created_at: NaiveDateTime,
225}
226
227// ──────────────────────────────────────────────
228// mfa: yauth_totp_secrets
229// ──────────────────────────────────────────────
230
231#[cfg(feature = "mfa")]
232#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
233#[diesel(table_name = yauth_totp_secrets)]
234#[diesel(check_for_backend(diesel::pg::Pg))]
235pub struct TotpSecret {
236    pub id: Uuid,
237    pub user_id: Uuid,
238    pub encrypted_secret: String,
239    pub verified: bool,
240    pub created_at: NaiveDateTime,
241}
242
243#[cfg(feature = "mfa")]
244#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
245#[diesel(table_name = yauth_totp_secrets)]
246pub struct NewTotpSecret {
247    pub id: Uuid,
248    pub user_id: Uuid,
249    pub encrypted_secret: String,
250    pub verified: bool,
251    pub created_at: NaiveDateTime,
252}
253
254// ──────────────────────────────────────────────
255// mfa: yauth_backup_codes
256// ──────────────────────────────────────────────
257
258#[cfg(feature = "mfa")]
259#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
260#[diesel(table_name = yauth_backup_codes)]
261#[diesel(check_for_backend(diesel::pg::Pg))]
262pub struct BackupCode {
263    pub id: Uuid,
264    pub user_id: Uuid,
265    pub code_hash: String,
266    pub used: bool,
267    pub created_at: NaiveDateTime,
268}
269
270#[cfg(feature = "mfa")]
271#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
272#[diesel(table_name = yauth_backup_codes)]
273pub struct NewBackupCode {
274    pub id: Uuid,
275    pub user_id: Uuid,
276    pub code_hash: String,
277    pub used: bool,
278    pub created_at: NaiveDateTime,
279}
280
281// ──────────────────────────────────────────────
282// oauth: yauth_oauth_accounts
283// ──────────────────────────────────────────────
284
285#[cfg(feature = "oauth")]
286#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
287#[diesel(table_name = yauth_oauth_accounts)]
288#[diesel(check_for_backend(diesel::pg::Pg))]
289pub struct OauthAccount {
290    pub id: Uuid,
291    pub user_id: Uuid,
292    pub provider: String,
293    pub provider_user_id: String,
294    pub access_token_enc: Option<String>,
295    pub refresh_token_enc: Option<String>,
296    pub created_at: NaiveDateTime,
297    pub expires_at: Option<NaiveDateTime>,
298    pub updated_at: NaiveDateTime,
299}
300
301#[cfg(feature = "oauth")]
302#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
303#[diesel(table_name = yauth_oauth_accounts)]
304pub struct NewOauthAccount {
305    pub id: Uuid,
306    pub user_id: Uuid,
307    pub provider: String,
308    pub provider_user_id: String,
309    pub access_token_enc: Option<String>,
310    pub refresh_token_enc: Option<String>,
311    pub created_at: NaiveDateTime,
312    pub expires_at: Option<NaiveDateTime>,
313    pub updated_at: NaiveDateTime,
314}
315
316// ──────────────────────────────────────────────
317// oauth: yauth_oauth_states
318// ──────────────────────────────────────────────
319
320#[cfg(feature = "oauth")]
321#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
322#[diesel(table_name = yauth_oauth_states)]
323#[diesel(check_for_backend(diesel::pg::Pg))]
324pub struct OauthState {
325    pub state: String,
326    pub provider: String,
327    pub redirect_url: Option<String>,
328    pub expires_at: NaiveDateTime,
329    pub created_at: NaiveDateTime,
330}
331
332#[cfg(feature = "oauth")]
333#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
334#[diesel(table_name = yauth_oauth_states)]
335pub struct NewOauthState {
336    pub state: String,
337    pub provider: String,
338    pub redirect_url: Option<String>,
339    pub expires_at: NaiveDateTime,
340    pub created_at: NaiveDateTime,
341}
342
343// ──────────────────────────────────────────────
344// api-key: yauth_api_keys
345// ──────────────────────────────────────────────
346
347#[cfg(feature = "api-key")]
348#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
349#[diesel(table_name = yauth_api_keys)]
350#[diesel(check_for_backend(diesel::pg::Pg))]
351pub struct ApiKey {
352    pub id: Uuid,
353    pub user_id: Uuid,
354    pub key_prefix: String,
355    pub key_hash: String,
356    pub name: String,
357    pub scopes: Option<serde_json::Value>,
358    pub last_used_at: Option<NaiveDateTime>,
359    pub expires_at: Option<NaiveDateTime>,
360    pub created_at: NaiveDateTime,
361}
362
363#[cfg(feature = "api-key")]
364#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
365#[diesel(table_name = yauth_api_keys)]
366pub struct NewApiKey {
367    pub id: Uuid,
368    pub user_id: Uuid,
369    pub key_prefix: String,
370    pub key_hash: String,
371    pub name: String,
372    pub scopes: Option<serde_json::Value>,
373    pub expires_at: Option<NaiveDateTime>,
374    pub created_at: NaiveDateTime,
375}
376
377// ──────────────────────────────────────────────
378// bearer: yauth_refresh_tokens
379// ──────────────────────────────────────────────
380
381#[cfg(feature = "bearer")]
382#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
383#[diesel(table_name = yauth_refresh_tokens)]
384#[diesel(check_for_backend(diesel::pg::Pg))]
385pub struct RefreshToken {
386    pub id: Uuid,
387    pub user_id: Uuid,
388    pub token_hash: String,
389    pub family_id: Uuid,
390    pub expires_at: NaiveDateTime,
391    pub revoked: bool,
392    pub created_at: NaiveDateTime,
393}
394
395#[cfg(feature = "bearer")]
396#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
397#[diesel(table_name = yauth_refresh_tokens)]
398pub struct NewRefreshToken {
399    pub id: Uuid,
400    pub user_id: Uuid,
401    pub token_hash: String,
402    pub family_id: Uuid,
403    pub expires_at: NaiveDateTime,
404    pub revoked: bool,
405    pub created_at: NaiveDateTime,
406}
407
408// ──────────────────────────────────────────────
409// magic-link: yauth_magic_links
410// ──────────────────────────────────────────────
411
412#[cfg(feature = "magic-link")]
413#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
414#[diesel(table_name = yauth_magic_links)]
415#[diesel(check_for_backend(diesel::pg::Pg))]
416pub struct MagicLink {
417    pub id: Uuid,
418    pub email: String,
419    pub token_hash: String,
420    pub expires_at: NaiveDateTime,
421    pub used: bool,
422    pub created_at: NaiveDateTime,
423}
424
425#[cfg(feature = "magic-link")]
426#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
427#[diesel(table_name = yauth_magic_links)]
428pub struct NewMagicLink {
429    pub id: Uuid,
430    pub email: String,
431    pub token_hash: String,
432    pub expires_at: NaiveDateTime,
433    pub created_at: NaiveDateTime,
434}
435
436// ──────────────────────────────────────────────
437// oauth2-server: yauth_oauth2_clients
438// ──────────────────────────────────────────────
439
440#[cfg(feature = "oauth2-server")]
441#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
442#[diesel(table_name = yauth_oauth2_clients)]
443#[diesel(check_for_backend(diesel::pg::Pg))]
444pub struct Oauth2Client {
445    pub id: Uuid,
446    pub client_id: String,
447    pub client_secret_hash: Option<String>,
448    pub redirect_uris: serde_json::Value,
449    pub client_name: Option<String>,
450    pub grant_types: serde_json::Value,
451    pub scopes: Option<serde_json::Value>,
452    pub is_public: bool,
453    pub created_at: NaiveDateTime,
454}
455
456#[cfg(feature = "oauth2-server")]
457#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
458#[diesel(table_name = yauth_oauth2_clients)]
459pub struct NewOauth2Client {
460    pub id: Uuid,
461    pub client_id: String,
462    pub client_secret_hash: Option<String>,
463    pub redirect_uris: serde_json::Value,
464    pub client_name: Option<String>,
465    pub grant_types: serde_json::Value,
466    pub scopes: Option<serde_json::Value>,
467    pub is_public: bool,
468    pub created_at: NaiveDateTime,
469}
470
471// ──────────────────────────────────────────────
472// oauth2-server: yauth_authorization_codes
473// ──────────────────────────────────────────────
474
475#[cfg(feature = "oauth2-server")]
476#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
477#[diesel(table_name = yauth_authorization_codes)]
478#[diesel(check_for_backend(diesel::pg::Pg))]
479pub struct AuthorizationCode {
480    pub id: Uuid,
481    pub code_hash: String,
482    pub client_id: String,
483    pub user_id: Uuid,
484    pub scopes: Option<serde_json::Value>,
485    pub redirect_uri: String,
486    pub code_challenge: String,
487    pub code_challenge_method: String,
488    pub expires_at: NaiveDateTime,
489    pub used: bool,
490    pub nonce: Option<String>,
491    pub created_at: NaiveDateTime,
492}
493
494#[cfg(feature = "oauth2-server")]
495#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
496#[diesel(table_name = yauth_authorization_codes)]
497pub struct NewAuthorizationCode {
498    pub id: Uuid,
499    pub code_hash: String,
500    pub client_id: String,
501    pub user_id: Uuid,
502    pub scopes: Option<serde_json::Value>,
503    pub redirect_uri: String,
504    pub code_challenge: String,
505    pub code_challenge_method: String,
506    pub expires_at: NaiveDateTime,
507    pub used: bool,
508    pub nonce: Option<String>,
509    pub created_at: NaiveDateTime,
510}
511
512// ──────────────────────────────────────────────
513// oauth2-server: yauth_consents
514// ──────────────────────────────────────────────
515
516#[cfg(feature = "oauth2-server")]
517#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
518#[diesel(table_name = yauth_consents)]
519#[diesel(check_for_backend(diesel::pg::Pg))]
520pub struct Consent {
521    pub id: Uuid,
522    pub user_id: Uuid,
523    pub client_id: String,
524    pub scopes: Option<serde_json::Value>,
525    pub created_at: NaiveDateTime,
526}
527
528#[cfg(feature = "oauth2-server")]
529#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
530#[diesel(table_name = yauth_consents)]
531pub struct NewConsent {
532    pub id: Uuid,
533    pub user_id: Uuid,
534    pub client_id: String,
535    pub scopes: Option<serde_json::Value>,
536    pub created_at: NaiveDateTime,
537}
538
539// ──────────────────────────────────────────────
540// oauth2-server: yauth_device_codes
541// ──────────────────────────────────────────────
542
543#[cfg(feature = "oauth2-server")]
544#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
545#[diesel(table_name = yauth_device_codes)]
546#[diesel(check_for_backend(diesel::pg::Pg))]
547pub struct DeviceCode {
548    pub id: Uuid,
549    pub device_code_hash: String,
550    pub user_code: String,
551    pub client_id: String,
552    pub scopes: Option<serde_json::Value>,
553    pub user_id: Option<Uuid>,
554    pub status: String,
555    pub interval: i32,
556    pub expires_at: NaiveDateTime,
557    pub last_polled_at: Option<NaiveDateTime>,
558    pub created_at: NaiveDateTime,
559}
560
561#[cfg(feature = "oauth2-server")]
562#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
563#[diesel(table_name = yauth_device_codes)]
564pub struct NewDeviceCode {
565    pub id: Uuid,
566    pub device_code_hash: String,
567    pub user_code: String,
568    pub client_id: String,
569    pub scopes: Option<serde_json::Value>,
570    pub user_id: Option<Uuid>,
571    pub status: String,
572    pub interval: i32,
573    pub expires_at: NaiveDateTime,
574    pub created_at: NaiveDateTime,
575}
576
577// ──────────────────────────────────────────────
578// account-lockout: yauth_account_locks
579// ──────────────────────────────────────────────
580
581#[cfg(feature = "account-lockout")]
582#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
583#[diesel(table_name = yauth_account_locks)]
584#[diesel(check_for_backend(diesel::pg::Pg))]
585pub struct AccountLock {
586    pub id: Uuid,
587    pub user_id: Uuid,
588    pub failed_count: i32,
589    pub locked_until: Option<NaiveDateTime>,
590    pub lock_count: i32,
591    pub locked_reason: Option<String>,
592    pub created_at: NaiveDateTime,
593    pub updated_at: NaiveDateTime,
594}
595
596#[cfg(feature = "account-lockout")]
597#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
598#[diesel(table_name = yauth_account_locks)]
599pub struct NewAccountLock {
600    pub id: Uuid,
601    pub user_id: Uuid,
602    pub failed_count: i32,
603    pub locked_until: Option<NaiveDateTime>,
604    pub lock_count: i32,
605    pub locked_reason: Option<String>,
606    pub created_at: NaiveDateTime,
607    pub updated_at: NaiveDateTime,
608}
609
610#[cfg(feature = "account-lockout")]
611#[derive(Debug, Clone, AsChangeset, Serialize, Deserialize)]
612#[diesel(table_name = yauth_account_locks)]
613pub struct UpdateAccountLock {
614    pub failed_count: Option<i32>,
615    pub locked_until: Option<Option<NaiveDateTime>>,
616    pub lock_count: Option<i32>,
617    pub locked_reason: Option<Option<String>>,
618    pub updated_at: Option<NaiveDateTime>,
619}
620
621// ──────────────────────────────────────────────
622// account-lockout: yauth_unlock_tokens
623// ──────────────────────────────────────────────
624
625#[cfg(feature = "account-lockout")]
626#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
627#[diesel(table_name = yauth_unlock_tokens)]
628#[diesel(check_for_backend(diesel::pg::Pg))]
629pub struct UnlockToken {
630    pub id: Uuid,
631    pub user_id: Uuid,
632    pub token_hash: String,
633    pub expires_at: NaiveDateTime,
634    pub created_at: NaiveDateTime,
635}
636
637#[cfg(feature = "account-lockout")]
638#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
639#[diesel(table_name = yauth_unlock_tokens)]
640pub struct NewUnlockToken {
641    pub id: Uuid,
642    pub user_id: Uuid,
643    pub token_hash: String,
644    pub expires_at: NaiveDateTime,
645    pub created_at: NaiveDateTime,
646}
647
648// ──────────────────────────────────────────────
649// webhooks: yauth_webhooks
650// ──────────────────────────────────────────────
651
652#[cfg(feature = "webhooks")]
653#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
654#[diesel(table_name = yauth_webhooks)]
655#[diesel(check_for_backend(diesel::pg::Pg))]
656pub struct Webhook {
657    pub id: Uuid,
658    pub url: String,
659    pub secret: String,
660    pub events: serde_json::Value,
661    pub active: bool,
662    pub created_at: NaiveDateTime,
663    pub updated_at: NaiveDateTime,
664}
665
666#[cfg(feature = "webhooks")]
667#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
668#[diesel(table_name = yauth_webhooks)]
669pub struct NewWebhook {
670    pub id: Uuid,
671    pub url: String,
672    pub secret: String,
673    pub events: serde_json::Value,
674    pub active: bool,
675    pub created_at: NaiveDateTime,
676    pub updated_at: NaiveDateTime,
677}
678
679#[cfg(feature = "webhooks")]
680#[derive(Debug, Clone, AsChangeset, Serialize, Deserialize)]
681#[diesel(table_name = yauth_webhooks)]
682pub struct UpdateWebhook {
683    pub url: Option<String>,
684    pub secret: Option<String>,
685    pub events: Option<serde_json::Value>,
686    pub active: Option<bool>,
687    pub updated_at: Option<NaiveDateTime>,
688}
689
690// ──────────────────────────────────────────────
691// webhooks: yauth_webhook_deliveries
692// ──────────────────────────────────────────────
693
694#[cfg(feature = "webhooks")]
695#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
696#[diesel(table_name = yauth_webhook_deliveries)]
697#[diesel(check_for_backend(diesel::pg::Pg))]
698pub struct WebhookDelivery {
699    pub id: Uuid,
700    pub webhook_id: Uuid,
701    pub event_type: String,
702    pub payload: serde_json::Value,
703    pub status_code: Option<i16>,
704    pub response_body: Option<String>,
705    pub success: bool,
706    pub attempt: i32,
707    pub created_at: NaiveDateTime,
708}
709
710#[cfg(feature = "webhooks")]
711#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
712#[diesel(table_name = yauth_webhook_deliveries)]
713pub struct NewWebhookDelivery {
714    pub id: Uuid,
715    pub webhook_id: Uuid,
716    pub event_type: String,
717    pub payload: serde_json::Value,
718    pub status_code: Option<i16>,
719    pub response_body: Option<String>,
720    pub success: bool,
721    pub attempt: i32,
722    pub created_at: NaiveDateTime,
723}
724
725// ──────────────────────────────────────────────
726// oidc: yauth_oidc_nonces
727// ──────────────────────────────────────────────
728
729#[cfg(feature = "oidc")]
730#[derive(Debug, Clone, Queryable, Selectable, Serialize, Deserialize)]
731#[diesel(table_name = yauth_oidc_nonces)]
732#[diesel(check_for_backend(diesel::pg::Pg))]
733pub struct OidcNonce {
734    pub id: Uuid,
735    pub nonce_hash: String,
736    pub authorization_code_id: Uuid,
737    pub created_at: NaiveDateTime,
738}
739
740#[cfg(feature = "oidc")]
741#[derive(Debug, Clone, Insertable, Serialize, Deserialize)]
742#[diesel(table_name = yauth_oidc_nonces)]
743pub struct NewOidcNonce {
744    pub id: Uuid,
745    pub nonce_hash: String,
746    pub authorization_code_id: Uuid,
747    pub created_at: NaiveDateTime,
748}