// What the owner sends to publish or change a listing (POST/PUT /api/v1/listings). // The node adds identity, time, proof-of-work and signature. import type { Listing } from "./verify.ts"; /** Listings expire after at most this many days (the protocol's limit). */ export const MAX_LIFETIME_DAYS = 30; export interface Draft { kind: string; category: string; geohash: string; price: { amount_cents: number; currency: "EUR"; period: "month" | "once" }; area_m2: number; rooms_x2: number; features: string[]; title: string; description: string; delegate?: string; expires_in_days: number; } /** The draft that reproduces a published listing, valid for a fresh term of `days`. */ export function draftFromListing(l: Listing, days = MAX_LIFETIME_DAYS): Draft { const period = l.price?.period === "once" ? "once" : "month"; const d: Draft = { kind: l.kind ?? "", category: l.category ?? "", geohash: l.geohash, price: { amount_cents: l.price?.amount_cents ?? 0, currency: "EUR", period }, area_m2: l.area_m2 ?? 0, rooms_x2: l.rooms_x2 ?? 0, features: l.features ?? [], title: l.title ?? "", description: l.description ?? "", expires_in_days: days, }; if (l.delegate) d.delegate = l.delegate; return d; }