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 icon: String { if isDeposit == true { return "percent" } if isAccount == true { return "building.columns.fill" } if isRecurring == true { return "arrow.clockwise" } return "banknote.fill" } var color: String { if isDeposit == true { return "ffa502" } if isAccount == true { return "7c3aed" } if isRecurring == true { return "00d4aa" } return "8888aa" } var typeLabel: String { if isDeposit == true { return "Вклад \(Int(interestRate ?? 0))%" } 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" } } 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" } 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? enum CodingKeys: String, CodingKey { case totalBalance = "total_balance" case totalDeposits = "total_deposits" case totalWithdrawals = "total_withdrawals" case categoriesCount = "categories_count" } }