99 lines
3.3 KiB
Swift
99 lines
3.3 KiB
Swift
import Foundation
|
|
import Persistence
|
|
|
|
extension Date {
|
|
/// The moment the trade stubs are stamped at: 23 September 2026, 09:14 in Amsterdam.
|
|
static let stub = Date(timeIntervalSince1970: 1_790_147_640)
|
|
}
|
|
|
|
extension User {
|
|
/// The demo buyer.
|
|
static let mara = User(id: .init(), email: "mara.v@example.com", displayName: "Mara Visser")
|
|
/// The demo seller, owner of the stub shop.
|
|
static let joost = User(id: .init(), email: "joost@kestrelrow.example", displayName: "Joost de Wit")
|
|
}
|
|
|
|
extension Offer {
|
|
/// An offer of €215 by the demo buyer on the stub listing, open for another 47 hours unless told otherwise.
|
|
static func stub(
|
|
listing: Listing = .stub(),
|
|
amountCents: Int = 21_500,
|
|
status: Status = .open
|
|
) -> Self {
|
|
.init(
|
|
id: .init(uuidString: "00000000-0000-0000-0000-0000000000AA") ?? .init(),
|
|
conversationID: .init(uuidString: "00000000-0000-0000-0000-0000000000CC") ?? .init(),
|
|
listing: listing,
|
|
buyer: .mara,
|
|
amountCents: amountCents,
|
|
status: status,
|
|
createdAt: .stub.addingTimeInterval(-3_600),
|
|
expiresAt: .stub.addingTimeInterval(47 * 3_600 + 60)
|
|
)
|
|
}
|
|
}
|
|
|
|
extension Sale {
|
|
/// A sale of the stub listing at €215 + €6, agreed at the stub moment, as far along as told.
|
|
static func stub(
|
|
priceCents: Int = 21_500,
|
|
paid: Bool = false,
|
|
sent: Bool = false,
|
|
received: Bool = false,
|
|
buyerRating: Int? = nil,
|
|
sellerRating: Int? = nil
|
|
) -> Self {
|
|
.init(
|
|
number: 48_213,
|
|
conversationID: .init(uuidString: "00000000-0000-0000-0000-0000000000CC") ?? .init(),
|
|
listing: .stub(soldAt: .stub),
|
|
buyer: .mara,
|
|
seller: .joost,
|
|
priceCents: priceCents,
|
|
askedCents: 24_000,
|
|
shippingCents: 600,
|
|
declared: .init(grade: "CGC 9.8 · cert 4312087-002", pageQuality: "White", printing: "First printing", notes: "Clean case."),
|
|
agreedAt: .stub,
|
|
paidAt: paid ? .stub.addingTimeInterval(360) : nil,
|
|
paymentNote: paid ? "iDEAL" : nil,
|
|
sentAt: sent ? .stub.addingTimeInterval(720) : nil,
|
|
shippingNote: sent ? "DHL 3S123" : nil,
|
|
receivedAt: received ? .stub.addingTimeInterval(1_080) : nil,
|
|
buyerRating: buyerRating,
|
|
sellerRating: sellerRating
|
|
)
|
|
}
|
|
}
|
|
|
|
extension Conversation {
|
|
/// A conversation about the stub listing, seen from the given side, holding the given entries.
|
|
static func stub(
|
|
side: Side = .buying,
|
|
listing: Listing? = .stub(),
|
|
entries: [Entry] = [],
|
|
unreadCount: Int = 0,
|
|
saleNumber: Int? = nil
|
|
) -> Self {
|
|
.init(
|
|
id: .init(uuidString: "00000000-0000-0000-0000-0000000000CC") ?? .init(),
|
|
buyer: .mara,
|
|
shop: .stub(),
|
|
listing: listing,
|
|
side: side,
|
|
entries: entries,
|
|
unreadCount: unreadCount,
|
|
saleNumber: saleNumber
|
|
)
|
|
}
|
|
}
|
|
|
|
extension Conversation.Entry {
|
|
/// Something a party wrote at the stub moment.
|
|
static func text(
|
|
_ body: String,
|
|
from sender: User
|
|
) -> Self {
|
|
.init(kind: .text, sender: sender, body: body, createdAt: .stub)
|
|
}
|
|
}
|