//
//  DeveloperView.swift
//  LotteryTracker
//
//  Created by aaa on 2026/1/24.
//

import SwiftUI
import Foundation

// 开发者视图
struct DeveloperView: View {
    @Environment(\.managedObjectContext) private var context
    @State private var showingTestDataAlert = false
    
    var body: some View {
        List {
            Section("测试功能") {
                Button("生成测试数据") {
                    generateTestData()
                }
                
                Button("检查所有开奖") {
                    checkAllDraws()
                }
                
                Button("重置所有设置") {
                    resetSettings()
                }
            }
            
            Section("调试信息") {
                HStack {
                    Text("数据库路径")
                    Spacer()
                    Text(getDatabasePath())
                        .font(.caption)
                        .foregroundColor(.secondary)
                        .lineLimit(1)
                }
                
                Button("显示日志") {
                    showLogs()
                }
            }
        }
        .navigationTitle("开发者选项")
        .alert("测试数据", isPresented: $showingTestDataAlert) {
            Button("确定", role: .cancel) { }
        } message: {
            Text("已生成50条测试数据")
        }
    }
    
    private func generateTestData() {
        print("生成测试数据功能")
        // 这里可以添加生成测试数据的代码
    }
    
    private func checkAllDraws() {
        print("检查所有开奖")
        // 这里可以添加检查开奖的代码
    }
    
    private func resetSettings() {
        if let bundleID = Bundle.main.bundleIdentifier {
            UserDefaults.standard.removePersistentDomain(forName: bundleID)
        }
        print("✅ 所有设置已重置")
    }
    
    private func getDatabasePath() -> String {
        let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
        return paths.first?.absoluteString ?? "未知"
    }
    
    private func showLogs() {
        print("显示日志...")
    }
}

// 预览
struct DeveloperView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationView {
            DeveloperView()
        }
    }
}
