Files
BalanceWatch/BalanceWatch/Models/CustomCategory.swift
T
wtandClaude Opus 5.5 0ccb7e1861 Implement contract v2 on the watch: accounts, rates, base currency, ledgers
- Sync and store accounts, transfers, rates and the baseCurrency setting;
  keep recurring, goal, debt and attachment records as raw payloads.
- Skip unknown entities on pull; preserve unknown payload fields of
  transactions, categories and budgets and send them back on re-save.
- Compute balances in integer cents: total balance, analytics and budgets
  in the base currency, per-account balances in the account currency,
  "нет курса C→B" warning when a rate is missing.
- Read-only accounts screen and an optional account picker when adding a
  transaction (currency follows the account).
- Shared ledgers: choose personal or shared in settings, join by code,
  separate SwiftData store, cursor and deletion journal per ledger,
  X-Balance-Ledger header on sync.
- Hide v2 features and do not push new entities when
  GET /v1/capabilities returns 404.
- Keep the wire id of records (lowercase UUID for new ones) so edits of
  records created by other clients do not create duplicates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 23:30:01 +07:00

55 lines
1.4 KiB
Swift

import Foundation
import SwiftData
@Model
final class CustomCategory {
var id: UUID = UUID()
var name: String = ""
var icon: String = "star.fill"
var emoji: String = ""
var colorName: String = "indigo"
var kindRawValue: String = "expense"
var createdAt: Date = Date.now
var syncUpdatedAt: Date = Date.now
var syncID: String?
var extraPayload: Data?
init(
id: UUID = UUID(),
name: String,
icon: String,
emoji: String = "",
colorName: String,
kind: TransactionKind,
createdAt: Date = .now,
syncUpdatedAt: Date = .now
) {
self.id = id
self.name = name
self.icon = icon
self.emoji = emoji
self.colorName = colorName
self.kindRawValue = kind.rawValue
self.createdAt = createdAt
self.syncID = id.uuidString.lowercased()
self.syncUpdatedAt = syncUpdatedAt
}
var wireID: String { syncID ?? id.uuidString }
var kind: TransactionKind {
get { TransactionKind(rawValue: kindRawValue) ?? .expense }
set { kindRawValue = newValue.rawValue }
}
var financeCategory: FinanceCategory {
FinanceCategory(
id: "custom-\(id.uuidString)",
name: name,
icon: icon,
emoji: emoji,
colorName: colorName
)
}
}