Files
pulse-mobile/PulseHealth/Models/SavingsModels.swift
Daniil Klimov 28fca1de89 feat: major app overhaul — API fixes, glassmorphism UI, health dashboard, notifications
API Integration:
- Fix logHabit: send "date" instead of "completed_at"
- Fix FinanceCategory: "icon" → "emoji" to match API
- Fix task priorities: remove level 4, keep 1-3 matching API
- Fix habit frequencies: map monthly/interval → "custom" for API
- Add token refresh (401 → auto retry with new token)
- Add proper error handling (remove try? in save functions, show errors in UI)
- Add date field to savings transactions
- Add MonthlyPaymentDetail and OverduePayment models
- Fix habit completedToday: compute on client from logs (API doesn't return it)
- Filter habits by day of week on client (daily/weekly/monthly/interval)

Design System (glassmorphism):
- New DesignSystem.swift: Theme colors, GlassCard modifier, GlowIcon, GlowStatCard
- Custom tab bar with per-tab glow colors (VStack layout, not ZStack overlay)
- Deep dark background #06060f across all views
- Glass cards with gradient fill + stroke throughout app
- App icon: glassmorphism style with teal glow

Health Dashboard:
- Compact ReadinessBanner with recommendation text
- 8 metric tiles: sleep, HR, HRV, steps, SpO2, respiratory rate, energy, distance
- Each tile with status indicator (good/ok/bad) and hint text
- Heart rate card (min/avg/max)
- Weekly trends card (averages)
- Recovery score (weighted: 40% sleep, 35% HRV, 25% RHR)
- Tips card with actionable recommendations
- Sleep detail view with hypnogram (step chart of phases)
- Sleep segments timeline from HealthKit (deep/rem/core/awake with exact times)
- Line chart replacing bar chart for weekly data
- Collect respiratory_rate and sleep phases with timestamps from HealthKit
- Background sync every ~30min via BGProcessingTask

Notifications:
- NotificationService for local push notifications
- Morning/evening reminders with native DatePicker (wheel)
- Payment reminders: 5 days, 1 day, and day-of for recurring savings
- Notification settings in Settings tab

UI Fixes:
- Fix color picker overflow: HStack → LazyVGrid 5 columns
- Fix sheet headers: shorter text, proper padding
- Fix task/habit toggle: separate tap zones (checkbox vs edit)
- Fix deprecated onChange syntax for iOS 17+
- Savings overview: real monthly payments and detailed overdues from API
- Settings: timezone as Menu picker, removed Telegram/server notifications sections
- All sheets use .presentationDetents([.large])

Config:
- project.yml: real DEVELOPMENT_TEAM, HealthKit + BackgroundModes capabilities
- Info.plist: BGTaskScheduler + UIBackgroundModes
- Assets.xcassets with AppIcon
- CLAUDE.md project documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 23:15:36 +03:00

209 lines
5.9 KiB
Swift

import Foundation
struct SavingsCategory: Codable, Identifiable {
let id: Int
var name: String
var description: String?
var isDeposit: Bool?
var isCredit: Bool?
var isAccount: Bool?
var isRecurring: Bool?
var isMulti: Bool?
var isClosed: Bool?
var currentAmount: Double?
var depositAmount: Double?
var interestRate: Double?
var depositStartDate: String?
var depositEndDate: String?
var recurringAmount: Double?
var recurringDay: Int?
var icon: String {
if isCredit == true { return "creditcard.fill" }
if isDeposit == true { return "percent" }
if isAccount == true { return "building.columns.fill" }
if isRecurring == true { return "arrow.clockwise" }
return "banknote.fill"
}
var colorHex: String {
if isCredit == true { return "ff4757" }
if isDeposit == true { return "ffa502" }
if isAccount == true { return "7c3aed" }
if isRecurring == true { return "00d4aa" }
return "8888aa"
}
var typeLabel: String {
if isCredit == true { return "Кредит \(Int(interestRate ?? 0))%" }
if isDeposit == true { return "Вклад \(Int(interestRate ?? 0))%" }
if isAccount == true { return "Счёт" }
if isRecurring == true { return "Регулярные" }
return "Накопление"
}
var typeEmoji: String {
if isCredit == true { return "💳" }
if isDeposit == true { return "🏦" }
if isAccount == true { return "🏧" }
if isRecurring == true { return "🔄" }
return "💰"
}
enum CodingKeys: String, CodingKey {
case id, name, description
case isDeposit = "is_deposit"
case isCredit = "is_credit"
case isAccount = "is_account"
case isRecurring = "is_recurring"
case isMulti = "is_multi"
case isClosed = "is_closed"
case currentAmount = "current_amount"
case depositAmount = "deposit_amount"
case interestRate = "interest_rate"
case depositStartDate = "deposit_start_date"
case depositEndDate = "deposit_end_date"
case recurringAmount = "recurring_amount"
case recurringDay = "recurring_day"
}
}
struct SavingsTransaction: Codable, Identifiable {
let id: Int
var categoryId: Int?
var userId: Int?
var amount: Double
var type: String // "deposit" или "withdrawal"
var description: String?
var date: String?
var createdAt: String?
var categoryName: String?
var userName: String?
var isDeposit: Bool { type == "deposit" }
var dateFormatted: String {
guard let d = date else { return "" }
let parts = String(d.prefix(10)).split(separator: "-")
guard parts.count == 3 else { return String(d.prefix(10)) }
return "\(parts[2]).\(parts[1]).\(parts[0])"
}
var dateOnly: String { String(date?.prefix(10) ?? "") }
enum CodingKeys: String, CodingKey {
case id, amount, type, description, date
case categoryId = "category_id"
case userId = "user_id"
case createdAt = "created_at"
case categoryName = "category_name"
case userName = "user_name"
}
}
struct SavingsStats: Codable {
var totalBalance: Double?
var totalDeposits: Double?
var totalWithdrawals: Double?
var categoriesCount: Int?
var monthlyPayments: Double?
var monthlyPaymentDetails: [MonthlyPaymentDetail]?
var overdueAmount: Double?
var overdueCount: Int?
var overdues: [OverduePayment]?
enum CodingKeys: String, CodingKey {
case totalBalance = "total_balance"
case totalDeposits = "total_deposits"
case totalWithdrawals = "total_withdrawals"
case categoriesCount = "categories_count"
case monthlyPayments = "monthly_payments"
case monthlyPaymentDetails = "monthly_payment_details"
case overdueAmount = "overdue_amount"
case overdueCount = "overdue_count"
case overdues
}
}
struct MonthlyPaymentDetail: Codable, Identifiable {
var id: Int { categoryId }
var categoryId: Int
var categoryName: String
var amount: Double
var day: Int
enum CodingKeys: String, CodingKey {
case categoryId = "category_id"
case categoryName = "category_name"
case amount, day
}
}
struct OverduePayment: Codable, Identifiable {
var id: String { "\(categoryId)-\(month)" }
var categoryId: Int
var categoryName: String
var userId: Int?
var userName: String?
var amount: Double
var dueDay: Int
var daysOverdue: Int
var month: String
enum CodingKeys: String, CodingKey {
case categoryId = "category_id"
case categoryName = "category_name"
case userId = "user_id"
case userName = "user_name"
case amount
case dueDay = "due_day"
case daysOverdue = "days_overdue"
case month
}
}
struct CreateSavingsTransactionRequest: Codable {
var categoryId: Int
var amount: Double
var type: String
var description: String?
var date: String?
enum CodingKeys: String, CodingKey {
case amount, type, description, date
case categoryId = "category_id"
}
}
// MARK: - SavingsRecurringPlan
struct SavingsRecurringPlan: Codable, Identifiable {
let id: Int
var categoryId: Int?
var userId: Int?
var effective: String?
var amount: Double
var day: Int?
var createdAt: String?
enum CodingKeys: String, CodingKey {
case id, amount, day
case categoryId = "category_id"
case userId = "user_id"
case effective
case createdAt = "created_at"
}
}
struct CreateRecurringPlanRequest: Codable {
var effective: String
var amount: Double
var day: Int?
}
struct UpdateRecurringPlanRequest: Codable {
var effective: String?
var amount: Double?
var day: Int?
}