// // DebugSeed.swift // Haru_Danim // // 개발 검증용 데모 데이터. 런치 인자 `-seedDemo YES`가 있을 때만 동작. (DEBUG 전용) // #if DEBUG import Foundation import SwiftData enum DebugSeed { /// `-autoStart <행동이름>` 런치 인자가 있으면 해당 행동의 시간 측정을 시작 (Live Activity 검증용) static func autoStartIfRequested(context: ModelContext) { guard let name = UserDefaults.standard.string(forKey: "autoStart") else { return } let descriptor = FetchDescriptor(predicate: #Predicate { $0.name == name }) guard let action = try? context.fetch(descriptor).first else { return } if action.runningSession == nil { context.insert(TimeSession(action: action, startAt: .now)) } LiveActivityManager.sync(context: context) } static func seedIfRequested(context: ModelContext) { guard UserDefaults.standard.bool(forKey: "seedDemo") else { return } let existing = (try? context.fetchCount(FetchDescriptor())) ?? 0 guard existing == 0 else { return } let study = Tag(name: "공부", colorHex: "#4A7A9D") let workout = Tag(name: "운동", colorHex: "#9D5B4A") let life = Tag(name: "생활", colorHex: "#2F6B4F") context.insert(study) context.insert(workout) context.insert(life) let reading = Action(name: "독서", symbolName: "book.fill", trackingType: .time, sortOrder: 0) reading.tags = [study] reading.isFavorite = true reading.promptsForNote = true let english = Action(name: "영어 공부", symbolName: "graduationcap.fill", trackingType: .time, sortOrder: 1) english.tags = [study] let running = Action(name: "달리기", symbolName: "figure.run", trackingType: .time, sortOrder: 2) running.tags = [workout] let pushup = Action(name: "팔굽혀펴기", symbolName: "dumbbell.fill", trackingType: .count, sortOrder: 3) pushup.tags = [workout] let water = Action(name: "물 마시기", symbolName: "drop.fill", trackingType: .count, sortOrder: 4) water.tags = [life] water.promptsForNote = true for action in [reading, english, running, pushup, water] { context.insert(action) } let now = Date.now let cal = Calendar.current func at(daysAgo: Int, hour: Int, minute: Int = 0) -> Date { let day = cal.date(byAdding: .day, value: -daysAgo, to: now)! return cal.date(bySettingHour: hour, minute: minute, second: 0, of: day)! } // 시간 기록 (며칠치) for daysAgo in 0...6 { context.insert(TimeSession(action: english, startAt: at(daysAgo: daysAgo, hour: 8), endAt: at(daysAgo: daysAgo, hour: 9, minute: 10))) if daysAgo % 2 == 0 { context.insert(TimeSession(action: running, startAt: at(daysAgo: daysAgo, hour: 7), endAt: at(daysAgo: daysAgo, hour: 7, minute: 40))) } if daysAgo % 3 != 0 { context.insert(TimeSession(action: reading, startAt: at(daysAgo: daysAgo, hour: 21), endAt: at(daysAgo: daysAgo, hour: 22, minute: 15))) } } // 자정을 걸치는 세션 (하루 경계 분할 확인용) + 메모 표시 확인용 let crossing = TimeSession(action: reading, startAt: at(daysAgo: 1, hour: 23, minute: 20), endAt: at(daysAgo: 0, hour: 0, minute: 40)) crossing.note = "자기 전에 소설 읽음. 재밌어서 늦게 잠" context.insert(crossing) // 진행 중 세션 context.insert(TimeSession(action: reading, startAt: now.addingTimeInterval(-25 * 60))) // 횟수 기록 for daysAgo in 0...6 { for i in 0..<(3 + daysAgo % 4) { context.insert(CountEntry(action: water, timestamp: at(daysAgo: daysAgo, hour: 9 + i * 2))) } if daysAgo % 2 == 0 { context.insert(CountEntry(action: pushup, timestamp: at(daysAgo: daysAgo, hour: 19), amount: 20)) } } // 메모가 달린 횟수 기록 (기록 탭 메모 표시 확인용) let notedWater = CountEntry(action: water, timestamp: at(daysAgo: 0, hour: 20)) notedWater.note = "자기 전 물 한 컵" context.insert(notedWater) // 목표 + 다짐 let toeic = Goal( title: "토익 700점 이상 받기", symbolName: "graduationcap.fill", colorHex: "#4A7A9D", startDate: cal.date(byAdding: .day, value: -10, to: now)!, endDate: cal.date(byAdding: .day, value: 30, to: now)! ) toeic.showsOnMain = true context.insert(toeic) let englishQuest = Quest(goal: toeic) englishQuest.targetAction = english englishQuest.measure = .time englishQuest.period = .daily englishQuest.targetSeconds = 3600 englishQuest.direction = .atLeast context.insert(englishQuest) let health = Goal( title: "건강한 생활 습관 만들기", symbolName: "heart.fill", colorHex: "#2F6B4F", startDate: cal.date(byAdding: .day, value: -20, to: now)!, endDate: nil ) context.insert(health) let waterQuest = Quest(goal: health) waterQuest.targetAction = water waterQuest.measure = .count waterQuest.period = .daily waterQuest.targetCount = 8 waterQuest.direction = .atLeast context.insert(waterQuest) let runQuest = Quest(goal: health) runQuest.targetAction = running runQuest.measure = .time runQuest.period = .daily runQuest.scheduleMode = .weekdays runQuest.weekdays = [2, 4, 6] runQuest.targetSeconds = 30 * 60 runQuest.direction = .atLeast context.insert(runQuest) } } #endif