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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
"""
Multi-User Sample Data for Calendar Application
"""

from datetime import datetime, timedelta
from typing import List, Dict, Any
from .enhanced_event_seed_data import generate_enhanced_event_sql
from .watch_channel_seed_data import get_watch_channel_sql

def get_multi_user_sample_data() -> Dict[str, Any]:
    """
    Generate sample data for multiple users demonstrating multi-user scenarios
    """
    
    # Sample users
    users = [
        {
            "user_id": "alice_manager",
            "email": "alice.manager@techcorp.com",
            "name": "Alice Johnson",
            "given_name": "Alice", 
            "family_name": "Johnson",
            "static_token": "ya29.A0ARrdaM-k9Vq7GzY2pL4mQf8sN1xT0bR3uHcJWv5yKzP6eF2.qwErTyUIopASDfGhJkLzXcVbNm12_34-56",
            "timezone": "America/New_York",
            "role": "Project Manager"
        },
        {
            "user_id": "bob_developer", 
            "email": "bob.smith@techcorp.com",
            "name": "Bob Smith",
            "given_name": "Bob",
            "family_name": "Smith", 
            "static_token": "ya29.A0ARrdaM-Zx8Nw3Q4pVb6Ls9R1mT0cG2uF5yH7kJd8sA1Lq2.wErtYuIoPaSdFgHjKlZxCvBnM987_65-43",
            "timezone": "America/Los_Angeles",
            "role": "Senior Developer"
        },
        {
            "user_id": "carol_designer",
            "email": "carol.white@techcorp.com", 
            "name": "Carol White",
            "given_name": "Carol",
            "family_name": "White",
            "static_token": "ya29.A0ARrdaM-b7Hc5Vn2Qm8R1sT4pL0xY9wK3uF6jZ2eRc1.QaWsEdRfTgHyJuIkOlPzXcVbNmKjHgf_21-098",
            "timezone": "Europe/London",
            "role": "UX Designer"
        },
        {
            "user_id": "dave_sales",
            "email": "dave.brown@techcorp.com",
            "name": "Dave Brown", 
            "given_name": "Dave",
            "family_name": "Brown",
            "static_token": "ya29.A0ARrdaM-p3Lk9Vb6Qw2Zx8N1sT4mH7gF5yR0uJc2ePq.ZxCvBnMlKjHgFfDsaQwErTyUiOpAsDfGhJk_77-11",
            "timezone": "America/Chicago",
            "role": "Sales Director"
        }
    ]
    
    # Alice's calendars (Project Manager)
    alice_calendars = [
        {
            "calendar_id": "alice-primary",
            "user_id": "alice_manager", 
            "summary": "Alice Johnson",
            "description": "Primary calendar for Alice Johnson - Project Manager",
            "time_zone": "America/New_York",
            "is_primary": True,
            "color_id": "1"
        },
        {
            "calendar_id": "alice-projects",
            "user_id": "alice_manager",
            "summary": "Project Management", 
            "description": "Project meetings, deadlines, and milestones",
            "time_zone": "America/New_York", 
            "is_primary": False,
            "color_id": "7"
        },
        {
            "calendar_id": "alice-team",
            "user_id": "alice_manager",
            "summary": "Team Coordination",
            "description": "Team meetings, 1-on-1s, and team events",
            "time_zone": "America/New_York",
            "is_primary": False, 
            "color_id": "11"
        }
    ]
    
    # Bob's calendars (Developer)
    bob_calendars = [
        {
            "calendar_id": "bob-primary",
            "user_id": "bob_developer",
            "summary": "Bob Smith",
            "description": "Primary calendar for Bob Smith - Senior Developer", 
            "time_zone": "America/Los_Angeles",
            "is_primary": True,
            "color_id": "2"
        },
        {
            "calendar_id": "bob-development", 
            "user_id": "bob_developer",
            "summary": "Development Schedule",
            "description": "Sprint planning, code reviews, and development tasks",
            "time_zone": "America/Los_Angeles",
            "is_primary": False,
            "color_id": "9" 
        },
        {
            "calendar_id": "bob-personal",
            "user_id": "bob_developer", 
            "summary": "Personal Time",
            "description": "Personal appointments and time off",
            "time_zone": "America/Los_Angeles",
            "is_primary": False,
            "color_id": "14"
        }
    ]
    
    # Carol's calendars (Designer)  
    carol_calendars = [
        {
            "calendar_id": "carol-primary",
            "user_id": "carol_designer",
            "summary": "Carol White",
            "description": "Primary calendar for Carol White - UX Designer",
            "time_zone": "Europe/London", 
            "is_primary": True,
            "color_id": "4"
        },
        {
            "calendar_id": "carol-design",
            "user_id": "carol_designer",
            "summary": "Design Work",
            "description": "Design sessions, user research, and creative time",
            "time_zone": "Europe/London",
            "is_primary": False,
            "color_id": "16"
        }
    ]
    
    # Dave's calendars (Sales)
    dave_calendars = [
        {
            "calendar_id": "dave-primary", 
            "user_id": "dave_sales",
            "summary": "Dave Brown",
            "description": "Primary calendar for Dave Brown - Sales Director",
            "time_zone": "America/Chicago",
            "is_primary": True,
            "color_id": "6"
        },
        {
            "calendar_id": "dave-sales",
            "user_id": "dave_sales", 
            "summary": "Sales Activities",
            "description": "Client meetings, sales calls, and deals",
            "time_zone": "America/Chicago",
            "is_primary": False,
            "color_id": "23"
        }
    ]
    
    # Sample events for each user
    base_date = datetime.now().replace(hour=9, minute=0, second=0, microsecond=0)
    
    alice_events = [
        {
            "event_id": "alice-event-1",
            "calendar_id": "alice-projects", 
            "user_id": "alice_manager",
            "summary": "Sprint Planning Meeting",
            "description": "Plan upcoming sprint with development team",
            "location": "Conference Room A",
            "start_datetime": base_date,
            "end_datetime": base_date + timedelta(hours=1),
            "status": "confirmed"
        },
        {
            "event_id": "alice-event-2",
            "calendar_id": "alice-team",
            "user_id": "alice_manager", 
            "summary": "1-on-1 with Bob",
            "description": "Weekly check-in with Bob Smith",
            "location": "Alice's Office",
            "start_datetime": base_date + timedelta(days=1, hours=2),
            "end_datetime": base_date + timedelta(days=1, hours=2, minutes=30),
            "status": "confirmed"
        },
        {
            "event_id": "alice-event-3",
            "calendar_id": "alice-primary",
            "user_id": "alice_manager",
            "summary": "Board Meeting",
            "description": "Monthly board meeting presentation", 
            "location": "Executive Conference Room",
            "start_datetime": base_date + timedelta(days=7),
            "end_datetime": base_date + timedelta(days=7, hours=2),
            "status": "confirmed"
        }
    ]
    
    bob_events = [
        {
            "event_id": "bob-event-1",
            "calendar_id": "bob-development",
            "user_id": "bob_developer",
            "summary": "Code Review Session", 
            "description": "Review pull requests from junior developers",
            "location": "Development Room",
            "start_datetime": base_date + timedelta(hours=3),
            "end_datetime": base_date + timedelta(hours=4),
            "status": "confirmed"
        },
        {
            "event_id": "bob-event-2",
            "calendar_id": "bob-primary",
            "user_id": "bob_developer",
            "summary": "Architecture Discussion",
            "description": "Discuss system architecture for new feature",
            "location": "Video Call", 
            "start_datetime": base_date + timedelta(days=2),
            "end_datetime": base_date + timedelta(days=2, hours=1, minutes=30),
            "status": "confirmed"
        },
        {
            "event_id": "bob-event-3",
            "calendar_id": "bob-personal",
            "user_id": "bob_developer",
            "summary": "Dentist Appointment",
            "description": "Annual dental checkup",
            "location": "Downtown Dental", 
            "start_datetime": base_date + timedelta(days=5, hours=5),
            "end_datetime": base_date + timedelta(days=5, hours=6),
            "status": "confirmed"
        }
    ]
    
    carol_events = [
        {
            "event_id": "carol-event-1",
            "calendar_id": "carol-design",
            "user_id": "carol_designer",
            "summary": "User Research Session",
            "description": "Interview users about new feature requirements",
            "location": "Research Lab",
            "start_datetime": base_date + timedelta(hours=1),
            "end_datetime": base_date + timedelta(hours=3),
            "status": "confirmed"
        },
        {
            "event_id": "carol-event-2", 
            "calendar_id": "carol-primary",
            "user_id": "carol_designer",
            "summary": "Design Review",
            "description": "Present mockups to stakeholders",
            "location": "Design Studio",
            "start_datetime": base_date + timedelta(days=3, hours=2),
            "end_datetime": base_date + timedelta(days=3, hours=3, minutes=30),
            "status": "confirmed"
        }
    ]
    
    dave_events = [
        {
            "event_id": "dave-event-1",
            "calendar_id": "dave-sales",
            "user_id": "dave_sales",
            "summary": "Client Demo",
            "description": "Product demonstration for potential enterprise client",
            "location": "Client Office",
            "start_datetime": base_date + timedelta(days=1),
            "end_datetime": base_date + timedelta(days=1, hours=2),
            "status": "confirmed"
        },
        {
            "event_id": "dave-event-2",
            "calendar_id": "dave-primary", 
            "user_id": "dave_sales",
            "summary": "Sales Team Meeting",
            "description": "Weekly sales team sync and pipeline review",
            "location": "Sales Conference Room",
            "start_datetime": base_date + timedelta(days=4),
            "end_datetime": base_date + timedelta(days=4, hours=1),
            "status": "confirmed"
        }
    ]

    settings =  [
        {"id": "alice_timezone", "user_id": "alice_manager", "value": "America/New_York"},
        {"id": "bob_timezone", "user_id": "bob_developer", "value": "America/Los_Angeles"},
        {"id": "carol_timezone", "user_id": "carol_designer", "value": "Europe/London"},
        {"id": "dave_timezone", "user_id": "dave_sales", "value": "America/Chicago"}
    ]

    scopes = [
        {"id": "scope-alice", "type": "user", "value": "alice.manager@techcorp.com"},
        {"id": "scope-bob", "type": "user", "value": "bob.smith@techcorp.com"},
        {"id": "scope-carol", "type": "user", "value": "carol.white@techcorp.com"},
        {"id": "scope-dave", "type": "user", "value": "dave.brown@techcorp.com"},
        {"id": "scope-group", "type": "group", "value": "product-team@techcorp.com"},
        {"id": "scope-domain", "type": "domain", "value": "techcorp.com"},
        {"id": "scope-public", "type": "default", "value":"public"}
    ]

    acls = [
        # Alice's calendar ACLs (owner of her calendars)
        {
            "id": "acl-alice-primary",
            "calendar_id": "alice-primary",
            "user_id": "alice_manager",
            "role": "owner",
            "scope_id": "scope-alice",
            "etag": "etag-alice-primary"
        },
        {
            "id": "acl-alice-projects",
            "calendar_id": "alice-projects",
            "user_id": "alice_manager",
            "role": "owner",
            "scope_id": "scope-alice",
            "etag": "etag-alice-projects"
        },
        {
            "id": "acl-alice-team",
            "calendar_id": "alice-team",
            "user_id": "alice_manager",
            "role": "owner",
            "scope_id": "scope-alice",
            "etag": "etag-alice-team"
        },
        # Bob's calendar ACLs (owner of his calendars)
        {
            "id": "acl-bob-primary",
            "calendar_id": "bob-primary",
            "user_id": "bob_developer",
            "role": "owner",
            "scope_id": "scope-bob",
            "etag": "etag-bob-primary"
        },
        {
            "id": "acl-bob-development",
            "calendar_id": "bob-development",
            "user_id": "bob_developer",
            "role": "owner",
            "scope_id": "scope-bob",
            "etag": "etag-bob-development"
        },
        {
            "id": "acl-bob-personal",
            "calendar_id": "bob-personal",
            "user_id": "bob_developer",
            "role": "owner",
            "scope_id": "scope-bob",
            "etag": "etag-bob-personal"
        },
        # Carol's calendar ACLs (owner of her calendars)
        {
            "id": "acl-carol-primary",
            "calendar_id": "carol-primary",
            "user_id": "carol_designer",
            "role": "owner",
            "scope_id": "scope-carol",
            "etag": "etag-carol-primary"
        },
        {
            "id": "acl-carol-design",
            "calendar_id": "carol-design",
            "user_id": "carol_designer",
            "role": "owner",
            "scope_id": "scope-carol",
            "etag": "etag-carol-design"
        },
        # Dave's calendar ACLs (owner of his calendars)
        {
            "id": "acl-dave-primary",
            "calendar_id": "dave-primary",
            "user_id": "dave_sales",
            "role": "owner",
            "scope_id": "scope-dave",
            "etag": "etag-dave-primary"
        },
        {
            "id": "acl-dave-sales",
            "calendar_id": "dave-sales",
            "user_id": "dave_sales",
            "role": "owner",
            "scope_id": "scope-dave",
            "etag": "etag-dave-sales"
        },
        # Shared access examples
        {
            "id": "acl-shared-1",
            "calendar_id": "alice-projects",
            "user_id": "alice_manager",
            "role": "writer",
            "scope_id": "scope-bob",
            "etag": "etag-shared-1"
        },
        {
            "id": "acl-shared-2",
            "calendar_id": "alice-projects",
            "user_id": "alice_manager",
            "role": "reader",
            "scope_id": "scope-carol",
            "etag": "etag-shared-2"
        }
    ]

    return {
        "users": users,
        "calendars": alice_calendars + bob_calendars + carol_calendars + dave_calendars,
        "events": alice_events + bob_events + carol_events + dave_events,
        "settings": settings,
        "scopes": scopes,
        "acls": acls,
        "description": "Multi-user sample data with 4 users (Alice-PM, Bob-Dev, Carol-Design, Dave-Sales) demonstrating isolated data per user"
    }


def get_multi_user_sql(database_name: str = "multi_user_calendar") -> str:
    """
    Generate SQL statements for multi-user sample data
    """
    data = get_multi_user_sample_data()
    
    sql_statements = []
    
    # Header
    sql_statements.append(f"-- Multi-User Calendar Sample Data for {database_name}")
    sql_statements.append(f"-- Generated on: {datetime.now().isoformat()}")
    sql_statements.append("-- Contains sample data for 4 users with isolated calendars and events")
    sql_statements.append("")
    
    # Users
    sql_statements.append("-- Users")
    sql_statements.append("INSERT INTO users (user_id, email, name, given_name, family_name, static_token, timezone, is_active, is_verified, created_at, updated_at) VALUES")
    
    user_values = []
    for user in data["users"]:
        # Escape single quotes by doubling them
        name = user['name'].replace("'", "''")
        given_name = user.get('given_name', '').replace("'", "''")
        family_name = user.get('family_name', '').replace("'", "''")
        
        user_values.append(
            f"('{user['user_id']}', '{user['email']}', '{name}', "
            f"'{given_name}', '{family_name}', "
            f"'{user['static_token']}', '{user['timezone']}', 1, 1, "
            f"datetime('now'), datetime('now'))"
        )
    
    sql_statements.append(",\n".join(user_values) + ";")
    sql_statements.append("")
    
    # Calendars
    sql_statements.append("-- Calendars")
    sql_statements.append("INSERT INTO calendars (calendar_id, user_id, summary, description, time_zone, is_primary, color_id, hidden, selected, deleted, created_at, updated_at) VALUES")
    
    calendar_values = []
    for calendar in data["calendars"]:
        # Escape single quotes by doubling them
        summary = calendar['summary'].replace("'", "''")
        description = calendar.get('description', '').replace("'", "''")
        
        calendar_values.append(
            f"('{calendar['calendar_id']}', '{calendar['user_id']}', '{summary}', "
            f"'{description}', '{calendar['time_zone']}', "
            f"{1 if calendar.get('is_primary') else 0}, '{calendar.get('color_id', '1')}', "
            f"0, 1, 0, datetime('now'), datetime('now'))"
        )
    
    sql_statements.append(",\n".join(calendar_values) + ";")
    sql_statements.append("")
    
    # Events  
    sql_statements = generate_enhanced_event_sql(sql_statements)
    
    # Colors (shared across users)
    sql_statements.append("-- Google Calendar Colors (shared across all users)")
    from data.google_colors import GOOGLE_CALENDAR_COLORS
    
    sql_statements.append("INSERT INTO colors (color_id, color_type, background, foreground, created_at, updated_at) VALUES")
    
    color_values = []
    for color in GOOGLE_CALENDAR_COLORS:
        color_values.append(
            f"('{color['color_id']}', '{color['color_type'].upper()}', '{color['background']}', "
            f"'{color['foreground']}', datetime('now'), datetime('now'))"
        )
    
    sql_statements.append(",\n".join(color_values) + ";")
    sql_statements.append("")

    # Settings
    sql_statements.append("-- Calendar Settings")
    sql_statements.append("INSERT INTO settings (id, user_id, value) VALUES")
    setting_values = []
    for setting in data["settings"]:
        setting_values.append(
            f"('{setting['id']}', '{setting['user_id']}', '{setting['value']}')"
        )
    sql_statements.append(",\n".join(setting_values) + ";\n")
    sql_statements.append("")

    # Scopes
    sql_statements.append("-- ACL Scopes")
    sql_statements.append("INSERT INTO scopes (id, type, value) VALUES")
    scope_values = []
    for scope in data["scopes"]:
        scope_values.append(
            f"('{scope['id']}', '{scope['type']}', '{scope['value']}')"
        )
    sql_statements.append(",\n".join(scope_values) + ";\n")
    sql_statements.append("")

    # ACLs
    sql_statements.append("-- Access Control Rules")
    sql_statements.append("INSERT INTO acls (id, calendar_id, user_id, role, scope_id, etag) VALUES")
    acl_values = []
    for acl in data["acls"]:
        acl_values.append(
            f"('{acl['id']}', '{acl['calendar_id']}', '{acl['user_id']}', "
            f"'{acl['role']}', '{acl['scope_id']}', '{acl['etag']}')"
        )
    sql_statements.append(",\n".join(acl_values) + ";\n")
    sql_statements.append("")

    sql_statements = get_watch_channel_sql(sql_statements)

    return "\n".join(sql_statements)