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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
openapi: 3.1.0
info:
  title: Api
  version: 0.1.0
  description: RAQIM  Document to Markdown conversion platform API
servers:
  - url: /api
    description: Base API path
tags:
  - name: health
    description: Health operations
  - name: auth
    description: Authentication operations
  - name: files
    description: File management
  - name: folders
    description: Folder management
  - name: convert
    description: Document conversion
  - name: shares
    description: File sharing
  - name: admin
    description: Admin operations
  - name: export
    description: File export

paths:
  /healthz:
    get:
      operationId: healthCheck
      tags: [health]
      summary: Health check
      responses:
        "200":
          description: Healthy
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HealthStatus"

  # ─── AUTH ───────────────────────────────────────────────
  /auth/register:
    post:
      operationId: registerUser
      tags: [auth]
      summary: Submit a join request (creates pending account)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RegisterBody"
      responses:
        "201":
          description: Join request submitted
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
        "409":
          description: Email already in use
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /auth/login:
    post:
      operationId: loginUser
      tags: [auth]
      summary: Login with email and password
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/LoginBody"
      responses:
        "200":
          description: Login successful
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuthResponse"
        "401":
          description: Invalid credentials or account not approved
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /auth/logout:
    post:
      operationId: logoutUser
      tags: [auth]
      summary: Logout and invalidate refresh token
      responses:
        "200":
          description: Logged out
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /auth/refresh:
    post:
      operationId: refreshToken
      tags: [auth]
      summary: Refresh access token
      responses:
        "200":
          description: New access token
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuthResponse"
        "401":
          description: Invalid or expired refresh token
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /auth/me:
    get:
      operationId: getCurrentUser
      tags: [auth]
      summary: Get current authenticated user
      responses:
        "200":
          description: Current user info
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"
        "401":
          description: Not authenticated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /auth/forgot-password:
    post:
      operationId: forgotPassword
      tags: [auth]
      summary: Request password reset email
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ForgotPasswordBody"
      responses:
        "200":
          description: Reset email sent if account exists
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /auth/reset-password:
    post:
      operationId: resetPassword
      tags: [auth]
      summary: Reset password using token
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ResetPasswordBody"
      responses:
        "200":
          description: Password reset successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
        "400":
          description: Invalid or expired token
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # ─── FOLDERS ────────────────────────────────────────────
  /folders:
    get:
      operationId: listFolders
      tags: [folders]
      summary: List folders for current user
      parameters:
        - in: query
          name: parentId
          schema:
            type: string
          description: Parent folder ID (null for root)
      responses:
        "200":
          description: List of folders
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Folder"
    post:
      operationId: createFolder
      tags: [folders]
      summary: Create a new folder
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateFolderBody"
      responses:
        "201":
          description: Folder created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Folder"

  /folders/{id}:
    patch:
      operationId: updateFolder
      tags: [folders]
      summary: Rename or move a folder
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateFolderBody"
      responses:
        "200":
          description: Folder updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Folder"
    delete:
      operationId: deleteFolder
      tags: [folders]
      summary: Move folder to trash
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Folder moved to trash
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  # ─── FILES ──────────────────────────────────────────────
  /files:
    get:
      operationId: listFiles
      tags: [files]
      summary: List files for current user
      parameters:
        - in: query
          name: folderId
          schema:
            type: string
          description: Folder ID (null for root)
        - in: query
          name: search
          schema:
            type: string
          description: Search by name
        - in: query
          name: trashed
          schema:
            type: boolean
          description: Show trashed files
        - in: query
          name: shared
          schema:
            type: boolean
          description: Show files shared with me
      responses:
        "200":
          description: List of files
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/FileItem"

  /files/{id}:
    get:
      operationId: getFile
      tags: [files]
      summary: Get file metadata
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: File metadata
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FileItem"
    patch:
      operationId: updateFile
      tags: [files]
      summary: Rename or move a file
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateFileBody"
      responses:
        "200":
          description: File updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FileItem"
    delete:
      operationId: deleteFile
      tags: [files]
      summary: Move file to trash
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: File moved to trash
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /files/{id}/content:
    get:
      operationId: getFileContent
      tags: [files]
      summary: Get file markdown content
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: File content
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FileContent"
    put:
      operationId: updateFileContent
      tags: [files]
      summary: Update file markdown content (auto-save)
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateContentBody"
      responses:
        "200":
          description: Content saved
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /files/{id}/restore:
    post:
      operationId: restoreFile
      tags: [files]
      summary: Restore file from trash
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: File restored
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /files/{id}/export:
    post:
      operationId: exportFile
      tags: [export]
      summary: Export file as DOCX or PDF
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ExportBody"
      responses:
        "200":
          description: Export URL
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ExportResponse"

  # ─── CONVERSION ─────────────────────────────────────────
  /convert:
    post:
      operationId: startConversion
      tags: [convert]
      summary: Start document conversion job
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/StartConversionBody"
      responses:
        "202":
          description: Conversion job started
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ConversionJob"

  /convert/{jobId}:
    get:
      operationId: getConversionStatus
      tags: [convert]
      summary: Get conversion job status and progress
      parameters:
        - in: path
          name: jobId
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Job status
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ConversionJob"

  /convert/upload:
    post:
      operationId: uploadAndConvert
      tags: [convert]
      summary: Upload file and start conversion
      responses:
        "202":
          description: Upload accepted and conversion started
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ConversionJob"

  # ─── SHARES ─────────────────────────────────────────────
  /shares:
    get:
      operationId: listShares
      tags: [shares]
      summary: List shares for current user (owned + shared with me)
      responses:
        "200":
          description: List of shares
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Share"
    post:
      operationId: createShare
      tags: [shares]
      summary: Share a file or folder with a user
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateShareBody"
      responses:
        "201":
          description: Share created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Share"

  /shares/{id}:
    patch:
      operationId: updateShare
      tags: [shares]
      summary: Update share permission
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateShareBody"
      responses:
        "200":
          description: Share updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Share"
    delete:
      operationId: deleteShare
      tags: [shares]
      summary: Remove a share
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Share removed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /shares/search-users:
    get:
      operationId: searchUsersForSharing
      tags: [shares]
      summary: Search users by email or username for sharing
      parameters:
        - in: query
          name: q
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Matching users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/UserSummary"

  # ─── ADMIN ──────────────────────────────────────────────
  /admin/users:
    get:
      operationId: adminListUsers
      tags: [admin]
      summary: List all users
      parameters:
        - in: query
          name: status
          schema:
            type: string
            enum: [active, suspended, pending]
        - in: query
          name: role
          schema:
            type: string
            enum: [user, admin]
        - in: query
          name: search
          schema:
            type: string
      responses:
        "200":
          description: List of users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/AdminUser"
    post:
      operationId: adminCreateUser
      tags: [admin]
      summary: Admin creates user directly (active status)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AdminCreateUserBody"
      responses:
        "201":
          description: User created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminUser"

  /admin/users/{id}:
    patch:
      operationId: adminUpdateUser
      tags: [admin]
      summary: Update user role or status
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AdminUpdateUserBody"
      responses:
        "200":
          description: User updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminUser"
    delete:
      operationId: adminDeleteUser
      tags: [admin]
      summary: Permanently delete a user
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: User deleted
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /admin/join-requests:
    get:
      operationId: listJoinRequests
      tags: [admin]
      summary: List pending join requests
      responses:
        "200":
          description: List of join requests
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/JoinRequest"

  /admin/join-requests/{id}:
    patch:
      operationId: processJoinRequest
      tags: [admin]
      summary: Approve or reject a join request
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ProcessJoinRequestBody"
      responses:
        "200":
          description: Request processed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /admin/stats:
    get:
      operationId: getAdminStats
      tags: [admin]
      summary: Get platform statistics
      responses:
        "200":
          description: Platform stats
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PlatformStats"

  /trash:
    get:
      operationId: listUserTrash
      tags: [files]
      summary: List trashed files and folders for current user
      responses:
        "200":
          description: Trashed items
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TrashItems"

  /trash/empty:
    delete:
      operationId: emptyUserTrash
      tags: [files]
      summary: Permanently delete all current user's trashed items
      responses:
        "200":
          description: Trash emptied
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

  /admin/trash:
    get:
      operationId: adminListTrash
      tags: [admin]
      summary: List ALL users' trashed files/folders (admin only)
      responses:
        "200":
          description: Trashed items
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TrashItems"

  /admin/trash/empty:
    delete:
      operationId: adminEmptyTrash
      tags: [admin]
      summary: Permanently delete all trashed items for current admin user
      responses:
        "200":
          description: Trash emptied
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"

components:
  schemas:
    HealthStatus:
      type: object
      properties:
        status:
          type: string
      required: [status]

    MessageResponse:
      type: object
      properties:
        message:
          type: string
      required: [message]

    ErrorResponse:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
      required: [error, message]

    # AUTH
    RegisterBody:
      type: object
      properties:
        email:
          type: string
          format: email
        password:
          type: string
        displayName:
          type: string
      required: [email, password]

    LoginBody:
      type: object
      properties:
        email:
          type: string
          format: email
        password:
          type: string
      required: [email, password]

    ForgotPasswordBody:
      type: object
      properties:
        email:
          type: string
          format: email
      required: [email]

    ResetPasswordBody:
      type: object
      properties:
        token:
          type: string
        password:
          type: string
      required: [token, password]

    AuthResponse:
      type: object
      properties:
        accessToken:
          type: string
        user:
          $ref: "#/components/schemas/User"
      required: [accessToken, user]

    User:
      type: object
      properties:
        id:
          type: string
        email:
          type: string
        displayName:
          type: string
        role:
          type: string
          enum: [user, admin]
        status:
          type: string
          enum: [pending, active, suspended]
        createdAt:
          type: string
          format: date-time
      required: [id, email, role, status, createdAt]

    UserSummary:
      type: object
      properties:
        id:
          type: string
        email:
          type: string
        displayName:
          type: string
      required: [id, email]

    # FOLDERS
    Folder:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        parentId:
          type: string
          nullable: true
        ownerId:
          type: string
        fileCount:
          type: integer
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      required: [id, name, ownerId, fileCount, createdAt, updatedAt]

    CreateFolderBody:
      type: object
      properties:
        name:
          type: string
        parentId:
          type: string
          nullable: true
      required: [name]

    UpdateFolderBody:
      type: object
      properties:
        name:
          type: string
        parentId:
          type: string
          nullable: true

    # FILES
    FileItem:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        folderId:
          type: string
          nullable: true
        ownerId:
          type: string
        originalName:
          type: string
        originalType:
          type: string
        sizeBytes:
          type: integer
        status:
          type: string
          enum: [uploading, queued, processing, done, failed, trashed]
        qualityScore:
          type: number
          nullable: true
        wordCount:
          type: integer
          nullable: true
        language:
          type: string
          nullable: true
        isShared:
          type: boolean
        sharedWith:
          type: array
          items:
            $ref: "#/components/schemas/UserSummary"
        permission:
          type: string
          enum: [owner, read, edit, full]
          nullable: true
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      required: [id, name, ownerId, originalName, originalType, sizeBytes, status, isShared, createdAt, updatedAt]

    UpdateFileBody:
      type: object
      properties:
        name:
          type: string
        folderId:
          type: string
          nullable: true

    FileContent:
      type: object
      properties:
        id:
          type: string
        markdownContent:
          type: string
        originalMarkdown:
          type: string
        updatedAt:
          type: string
          format: date-time
      required: [id, markdownContent, originalMarkdown, updatedAt]

    UpdateContentBody:
      type: object
      properties:
        markdownContent:
          type: string
      required: [markdownContent]

    ExportBody:
      type: object
      properties:
        format:
          type: string
          enum: [md, docx, pdf, print]
        fileName:
          type: string
      required: [format]

    ExportResponse:
      type: object
      properties:
        downloadUrl:
          type: string
        fileName:
          type: string
        format:
          type: string
      required: [downloadUrl, fileName, format]

    # CONVERSION
    StartConversionBody:
      type: object
      properties:
        fileId:
          type: string
        pageStart:
          type: integer
          nullable: true
        pageEnd:
          type: integer
          nullable: true
      required: [fileId]

    ConversionJob:
      type: object
      properties:
        jobId:
          type: string
        fileId:
          type: string
        status:
          type: string
          enum: [queued, analyzing, routing, ocr, layout, scoring, merging, cleanup, done, failed]
        progress:
          type: integer
          description: 0-100
        steps:
          type: array
          items:
            $ref: "#/components/schemas/ConversionStep"
        queuePosition:
          type: integer
          nullable: true
        elapsedSeconds:
          type: integer
          nullable: true
        estimatedSeconds:
          type: integer
          nullable: true
        errorMessage:
          type: string
          nullable: true
        createdAt:
          type: string
          format: date-time
      required: [jobId, fileId, status, progress, steps, createdAt]

    ConversionStep:
      type: object
      properties:
        name:
          type: string
        status:
          type: string
          enum: [pending, running, done, failed]
        label:
          type: string
      required: [name, status, label]

    # SHARES
    Share:
      type: object
      properties:
        id:
          type: string
        fileId:
          type: string
          nullable: true
        folderId:
          type: string
          nullable: true
        ownerId:
          type: string
        sharedWithId:
          type: string
        permission:
          type: string
          enum: [read, edit, full]
        fileName:
          type: string
          nullable: true
        folderName:
          type: string
          nullable: true
        ownerEmail:
          type: string
        sharedWithEmail:
          type: string
        createdAt:
          type: string
          format: date-time
      required: [id, ownerId, sharedWithId, permission, ownerEmail, sharedWithEmail, createdAt]

    CreateShareBody:
      type: object
      properties:
        fileId:
          type: string
          nullable: true
        folderId:
          type: string
          nullable: true
        sharedWithId:
          type: string
        permission:
          type: string
          enum: [read, edit, full]
      required: [sharedWithId, permission]

    UpdateShareBody:
      type: object
      properties:
        permission:
          type: string
          enum: [read, edit, full]
      required: [permission]

    # ADMIN
    AdminUser:
      type: object
      properties:
        id:
          type: string
        email:
          type: string
        displayName:
          type: string
          nullable: true
        role:
          type: string
          enum: [user, admin]
        status:
          type: string
          enum: [pending, active, suspended]
        fileCount:
          type: integer
        lastLoginAt:
          type: string
          format: date-time
          nullable: true
        createdAt:
          type: string
          format: date-time
      required: [id, email, role, status, fileCount, createdAt]

    AdminCreateUserBody:
      type: object
      properties:
        email:
          type: string
          format: email
        password:
          type: string
        displayName:
          type: string
        role:
          type: string
          enum: [user, admin]
      required: [email, password]

    AdminUpdateUserBody:
      type: object
      properties:
        role:
          type: string
          enum: [user, admin]
        status:
          type: string
          enum: [active, suspended]

    JoinRequest:
      type: object
      properties:
        id:
          type: string
        email:
          type: string
        displayName:
          type: string
          nullable: true
        requestedAt:
          type: string
          format: date-time
      required: [id, email, requestedAt]

    ProcessJoinRequestBody:
      type: object
      properties:
        action:
          type: string
          enum: [approve, reject]
        reason:
          type: string
          nullable: true
      required: [action]

    PlatformStats:
      type: object
      properties:
        totalUsers:
          type: integer
        activeUsers:
          type: integer
        pendingRequests:
          type: integer
        totalFiles:
          type: integer
        filesConvertedToday:
          type: integer
        filesConvertedThisWeek:
          type: integer
        successRate:
          type: number
        averageQualityScore:
          type: number
        averageProcessingSeconds:
          type: number
        topFileType:
          type: string
        conversionsByType:
          type: object
          additionalProperties:
            type: integer
      required: [totalUsers, activeUsers, pendingRequests, totalFiles, filesConvertedToday, filesConvertedThisWeek, successRate, averageQualityScore, averageProcessingSeconds]

    TrashItems:
      type: object
      properties:
        files:
          type: array
          items:
            $ref: "#/components/schemas/FileItem"
        folders:
          type: array
          items:
            $ref: "#/components/schemas/Folder"
      required: [files, folders]