Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Immo-Ka iOS9// File : ImmoKa/System/AppIntents.swift10// Description : App Intents et raccourcis Siri — chercher des propriétés11// dans une ville, ouvrir le marché d'une ville, ouvrir les12// favoris, demander le prix demandé médian d'une ville13// (réponse parlée, sans ouvrir l'app).14// Module : ImmoKa15// Repository : https://git.spboucher.ai/immo-ka-ios-v316// Project Website : https://www.immo-ka.com17// Created : 2026-11-2818// Last Modified : 2026-11-2819//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author : Simon-Pierre Boucher25// Position : Professor of Finance26// Institution : Université du Québec en Outaouais (UQO)27// Department : Département des sciences administratives28// Organization : SP Boucher29//30// Website : https://spboucher.ai31// Git : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General : info@spboucher.ai38// Professional : contact@spboucher.ai39// Direct : simon@spboucher.ai40// Research : research@spboucher.ai41// Development : dev@spboucher.ai42// Support : support@spboucher.ai43// Security/Admin : admin@spboucher.ai44// Notifications : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification : Public71// Distribution : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License : None specified (no license file in this repository)85// Maintainer : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import AppIntents93import Foundation94import Observation9596/// Lien à ouvrir à l'arrivée dans l'app (posé par un intent, lu par la racine).97@MainActor98@Observable99final class DeepLinkInbox {100 static let shared = DeepLinkInbox()101 var pending: URL?102103 /// `immoka://recherche?city=…&type=…&price_max=…`104 static func searchURL(city: String?, type: String?, priceMax: Int?) -> URL {105 var c = URLComponents()106 c.scheme = "immoka"; c.host = "recherche"107 let items = [URLQueryItem(name: "city", value: city), URLQueryItem(name: "type", value: type),108 URLQueryItem(name: "price_max", value: priceMax.map(String.init))].filter { !($0.value ?? "").isEmpty }109 if !items.isEmpty { c.queryItems = items }110 return c.url ?? URL(string: "immoka://recherche")!111 }112}113114enum PropertyTypeOption: String, AppEnum {115 case maison = "Maison", condo = "Condo", duplex = "Duplex", triplex = "Triplex", multiplex = "Multiplex", terrain = "Terrain", chalet = "Chalet"116117 static let typeDisplayRepresentation: TypeDisplayRepresentation = "Type de propriété"118 static let caseDisplayRepresentations: [PropertyTypeOption: DisplayRepresentation] = [119 .maison: "Maison", .condo: "Condo", .duplex: "Duplex", .triplex: "Triplex", .multiplex: "Multiplex", .terrain: "Terrain", .chalet: "Chalet",120 ]121}122123struct SearchPropertiesIntent: AppIntent {124 static let title: LocalizedStringResource = "Chercher des propriétés"125 static let description = IntentDescription("Ouvre la carte d'Immo-Ka sur les propriétés à vendre d'une ville.")126 static let openAppWhenRun = true127128 @Parameter(title: "Ville", requestValueDialog: "Dans quelle ville ?")129 var city: String130131 @Parameter(title: "Type de propriété")132 var type: PropertyTypeOption?133134 @Parameter(title: "Prix maximal", inclusiveRange: (10_000, 50_000_000))135 var priceMax: Int?136137 static var parameterSummary: some ParameterSummary {138 Summary("Chercher des propriétés à \(\.$city)") {139 \.$type140 \.$priceMax141 }142 }143144 @MainActor145 func perform() async throws -> some IntentResult {146 DeepLinkInbox.shared.pending = DeepLinkInbox.searchURL(city: city, type: type?.rawValue, priceMax: priceMax)147 return .result()148 }149}150151struct OpenMarketIntent: AppIntent {152 static let title: LocalizedStringResource = "Ouvrir le marché"153 static let description = IntentDescription("Ouvre le marché immobilier du Québec dans Immo-Ka.")154 static let openAppWhenRun = true155156 @MainActor157 func perform() async throws -> some IntentResult {158 DeepLinkInbox.shared.pending = URL(string: "immoka://marche")159 return .result()160 }161}162163struct OpenFavoritesIntent: AppIntent {164 static let title: LocalizedStringResource = "Ouvrir mes favoris"165 static let description = IntentDescription("Ouvre vos propriétés favorites dans Immo-Ka.")166 static let openAppWhenRun = true167168 @MainActor169 func perform() async throws -> some IntentResult {170 DeepLinkInbox.shared.pending = URL(string: "immoka://favoris")171 return .result()172 }173}174175/// Réponse parlée : le prix demandé médian d'une ville, tel que le service le publie. Rien n'est inventé :176/// ville inconnue ou service injoignable, l'intent le dit.177struct AskingPriceIntent: AppIntent {178 static let title: LocalizedStringResource = "Prix demandé médian d'une ville"179 static let description = IntentDescription("Donne le prix demandé médian des propriétés à vendre dans une ville, et le nombre de propriétés.")180181 @Parameter(title: "Ville", requestValueDialog: "Pour quelle ville ?")182 var city: String183184 static var parameterSummary: some ParameterSummary { Summary("Prix demandé médian à \(\.$city)") }185186 func perform() async throws -> some IntentResult & ProvidesDialog {187 .result(dialog: IntentDialog(stringLiteral: await AskingPriceIntent.answer(for: city)))188 }189190 /// Phrase de réponse pour une ville.191 static func answer(for city: String) async -> String {192 let slug = Fmt.slug(city)193 guard !slug.isEmpty else { return "Je n'ai pas compris le nom de la ville." }194 do {195 let m = try await APIClient.shared.market(place: slug, kind: "municipalite")196 return sentence(m, asked: city)197 } catch APIError.notFound {198 return "Immo-Ka ne connaît pas de ville nommée \(city)."199 } catch let e as APIError where e.isOffline {200 return "Immo-Ka est injoignable pour l'instant."201 } catch {202 return "Je n'ai pas pu obtenir le marché de \(city)."203 }204 }205206 /// Fonction pure, testée : la phrase dit qu'il s'agit de prix demandés, pas de prix de vente.207 static func sentence(_ m: MarketPortrait, asked: String) -> String {208 guard let median = m.askMedian, let n = m.inventory, n > 0 else {209 return "Immo-Ka n'a pas assez de propriétés à vendre à \(m.place.name.isEmpty ? asked : m.place.name) pour donner un prix médian."210 }211 var t = "À \(m.place.name), le prix demandé médian est de \(Fmt.money(median)), sur \(Fmt.plural(n, "propriété à vendre", "propriétés à vendre"))."212 if let s = m.sales.first(where: { $0.family == "residentiel" }), let sm = s.median {213 t += " Les ventes réelles des douze derniers mois connus ont un prix médian de \(Fmt.money(sm))."214 }215 return t216 }217}218219struct ImmoKaShortcuts: AppShortcutsProvider {220 static var appShortcuts: [AppShortcut] {221 AppShortcut(intent: SearchPropertiesIntent(),222 phrases: ["Chercher des propriétés avec \(.applicationName)", "Chercher une maison avec \(.applicationName)"],223 shortTitle: "Chercher des propriétés", systemImageName: "map")224 AppShortcut(intent: AskingPriceIntent(),225 phrases: ["Prix demandé médian avec \(.applicationName)", "Quel est le prix des maisons selon \(.applicationName)"],226 shortTitle: "Prix demandé médian", systemImageName: "chart.bar.xaxis")227 AppShortcut(intent: OpenMarketIntent(),228 phrases: ["Ouvrir le marché dans \(.applicationName)"],229 shortTitle: "Marché", systemImageName: "chart.xyaxis.line")230 AppShortcut(intent: OpenFavoritesIntent(),231 phrases: ["Ouvrir mes favoris dans \(.applicationName)"],232 shortTitle: "Favoris", systemImageName: "heart")233 }234}235