mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-12-03 01:08:45 +00:00
feat: Add analytics, security, and currency SDK modules with comprehensive API endpoints across Elixir and Go SDKs
- Add AnalyticsAPI with churn prediction (predict, metrics, at-risk), market analytics (metrics, competitors, opportunities), predictive maintenance (metrics, assets, alerts, predict), and pricing optimization (metrics, optimize, elasticity) endpoints - Add SecurityAPI with fraud detection (analyze, alerts, update status, metrics, patterns) and SIM swap protection (verify, history) endpoints - Add CurrencyAPI with currency conversion (convert, exchange rates, rate
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
package com.telecom
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
/**
|
||||
* Analytics API for churn prediction, market analysis, and pricing optimization
|
||||
*/
|
||||
class AnalyticsAPI(private val httpClient: HTTPClient) {
|
||||
|
||||
/**
|
||||
* Predict churn risk for a profile
|
||||
*/
|
||||
suspend fun predictChurn(profileId: String): ChurnPrediction {
|
||||
return httpClient.post("/api/v1/analytics/churn/predict",
|
||||
mapOf("profile_id" to profileId))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get churn metrics
|
||||
*/
|
||||
suspend fun getChurnMetrics(period: String = "monthly"): ChurnMetrics {
|
||||
return httpClient.get("/api/v1/analytics/churn/metrics",
|
||||
mapOf("period" to period))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get at-risk customers
|
||||
*/
|
||||
suspend fun getAtRiskCustomers(
|
||||
riskLevel: ChurnRiskLevel,
|
||||
limit: Int = 100
|
||||
): List<ChurnPrediction> {
|
||||
return httpClient.post("/api/v1/analytics/churn/at-risk",
|
||||
mapOf(
|
||||
"risk_level" to riskLevel.value,
|
||||
"limit" to limit
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get market metrics
|
||||
*/
|
||||
suspend fun getMarketMetrics(period: String = "monthly"): MarketMetrics {
|
||||
return httpClient.get("/api/v1/analytics/market/metrics",
|
||||
mapOf("period" to period))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get competitor analysis
|
||||
*/
|
||||
suspend fun getCompetitors(): JsonObject {
|
||||
return httpClient.get("/api/v1/analytics/market/competitors")
|
||||
}
|
||||
|
||||
/**
|
||||
* Get market opportunities
|
||||
*/
|
||||
suspend fun getMarketOpportunities(): JsonObject {
|
||||
return httpClient.get("/api/v1/analytics/market/opportunities")
|
||||
}
|
||||
|
||||
/**
|
||||
* Get maintenance metrics
|
||||
*/
|
||||
suspend fun getMaintenanceMetrics(period: String = "monthly"): MaintenanceMetrics {
|
||||
return httpClient.get("/api/v1/analytics/maintenance/metrics",
|
||||
mapOf("period" to period))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get assets health
|
||||
*/
|
||||
suspend fun getAssetsHealth(): JsonObject {
|
||||
return httpClient.get("/api/v1/analytics/maintenance/assets")
|
||||
}
|
||||
|
||||
/**
|
||||
* Get maintenance alerts
|
||||
*/
|
||||
suspend fun getMaintenanceAlerts(): JsonObject {
|
||||
return httpClient.get("/api/v1/analytics/maintenance/alerts")
|
||||
}
|
||||
|
||||
/**
|
||||
* Predict failure for an asset
|
||||
*/
|
||||
suspend fun predictFailure(assetId: String): JsonObject {
|
||||
return httpClient.post("/api/v1/analytics/maintenance/predict/$assetId", emptyMap())
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pricing metrics
|
||||
*/
|
||||
suspend fun getPricingMetrics(period: String = "monthly"): PricingMetrics {
|
||||
return httpClient.get("/api/v1/analytics/pricing/metrics",
|
||||
mapOf("period" to period))
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimize pricing for rate plans
|
||||
*/
|
||||
suspend fun optimizePricing(
|
||||
ratePlanIds: List<String>,
|
||||
strategy: String = "revenue_maximization"
|
||||
): List<PricingOptimizationResult> {
|
||||
return httpClient.post("/api/v1/analytics/pricing/optimize",
|
||||
mapOf(
|
||||
"rate_plan_ids" to ratePlanIds,
|
||||
"strategy" to strategy
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get price elasticity data
|
||||
*/
|
||||
suspend fun getPriceElasticity(): JsonObject {
|
||||
return httpClient.get("/api/v1/analytics/pricing/elasticity")
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ChurnPrediction(
|
||||
val profileId: String,
|
||||
val riskLevel: String,
|
||||
val riskScore: Double,
|
||||
val predictedChurnDate: String? = null,
|
||||
val reasons: List<String>,
|
||||
val recommendations: List<String>,
|
||||
val lastUpdated: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ChurnMetrics(
|
||||
val period: String,
|
||||
val totalSubscribers: Long,
|
||||
val churnedSubscribers: Long,
|
||||
val churnRate: Double,
|
||||
val monthlyChurnRate: Double,
|
||||
val annualChurnRate: Double,
|
||||
val averageTenureDays: Double,
|
||||
val riskDistribution: Map<String, Long>,
|
||||
val generatedAt: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class MarketMetrics(
|
||||
val period: String,
|
||||
val totalMarketSize: Long,
|
||||
val ourSubscribers: Long,
|
||||
val marketShare: Double,
|
||||
val growthRate: Double,
|
||||
val byCountry: Map<String, JsonObject>,
|
||||
val generatedAt: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class MaintenanceMetrics(
|
||||
val period: String,
|
||||
val totalAssets: Long,
|
||||
val healthyAssets: Long,
|
||||
val assetsNeedingAttention: Long,
|
||||
val uptime: Double,
|
||||
val meanTimeToFailure: Double,
|
||||
val meanTimeToRepair: Double,
|
||||
val generatedAt: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class PricingMetrics(
|
||||
val period: String,
|
||||
val totalRevenue: Double,
|
||||
val arpu: Double,
|
||||
val priceElasticity: Double,
|
||||
val competitiveIndex: Double,
|
||||
val optimizationRoi: Double,
|
||||
val generatedAt: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class PricingOptimizationResult(
|
||||
val ratePlanId: String,
|
||||
val strategy: String,
|
||||
val currentPrice: Double,
|
||||
val optimalPrice: Double,
|
||||
val priceChangePct: Double,
|
||||
val expectedRevenue: Double,
|
||||
val expectedDemand: Double,
|
||||
val confidence: Double,
|
||||
val reasoning: List<String>,
|
||||
val risks: List<String>,
|
||||
val recommendations: List<String>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
enum class ChurnRiskLevel(val value: String) {
|
||||
LOW("low"),
|
||||
MEDIUM("medium"),
|
||||
HIGH("high"),
|
||||
CRITICAL("critical")
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.telecom
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Currency and Billing API
|
||||
*/
|
||||
class CurrencyAPI(private val httpClient: HTTPClient) {
|
||||
|
||||
/**
|
||||
* Convert currency
|
||||
*/
|
||||
suspend fun convert(from: String, to: String, amount: Double): ConvertResponse {
|
||||
return httpClient.post("/api/v1/currency/convert",
|
||||
mapOf(
|
||||
"from" to from,
|
||||
"to" to to,
|
||||
"amount" to amount
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get exchange rate between currencies
|
||||
*/
|
||||
suspend fun getExchangeRate(from: String, to: String): ExchangeRate {
|
||||
return httpClient.get("/api/v1/currency/exchange/$from/$to")
|
||||
}
|
||||
|
||||
/**
|
||||
* Get exchange rate history
|
||||
*/
|
||||
suspend fun getExchangeRateHistory(from: String, to: String, days: Int = 30): List<ExchangeRate> {
|
||||
return httpClient.get("/api/v1/currency/exchange/$from/$to/history",
|
||||
mapOf("days" to days))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported currencies
|
||||
*/
|
||||
suspend fun getSupportedCurrencies(): List<Currency> {
|
||||
return httpClient.get("/api/v1/currency/currencies")
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh exchange rates
|
||||
*/
|
||||
suspend fun refreshExchangeRates(): JsonObject {
|
||||
return httpClient.post("/api/v1/currency/exchange/refresh", emptyMap())
|
||||
}
|
||||
|
||||
/**
|
||||
* Process billing transaction
|
||||
*/
|
||||
suspend fun processBilling(billingData: Map<String, Any>): BillingTransaction {
|
||||
return httpClient.post("/api/v1/currency/billing", billingData)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get billing history for a profile
|
||||
*/
|
||||
suspend fun getBillingHistory(profileId: String, limit: Int = 50): List<BillingTransaction> {
|
||||
return httpClient.get("/api/v1/currency/billing/history/$profileId",
|
||||
mapOf("limit" to limit))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get billing summary for a profile
|
||||
*/
|
||||
suspend fun getBillingSummary(profileId: String, period: String = "monthly"): BillingSummary {
|
||||
return httpClient.get("/api/v1/currency/billing/summary/$profileId",
|
||||
mapOf("period" to period))
|
||||
}
|
||||
|
||||
/**
|
||||
* Process refund
|
||||
*/
|
||||
suspend fun processRefund(transactionId: String, reason: String): BillingTransaction {
|
||||
return httpClient.post("/api/v1/currency/billing/refund/$transactionId",
|
||||
mapOf("reason" to reason))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get billing analytics
|
||||
*/
|
||||
suspend fun getBillingAnalytics(period: String = "monthly"): JsonObject {
|
||||
return httpClient.get("/api/v1/currency/billing/analytics",
|
||||
mapOf("period" to period))
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ConvertRequest(
|
||||
val from: String,
|
||||
val to: String,
|
||||
val amount: Double
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ConvertResponse(
|
||||
val from: String,
|
||||
val to: String,
|
||||
val amount: Double,
|
||||
val converted: Double,
|
||||
val rate: Double,
|
||||
val timestamp: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ExchangeRate(
|
||||
val from: String,
|
||||
val to: String,
|
||||
val rate: Double,
|
||||
val timestamp: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Currency(
|
||||
val code: String,
|
||||
val name: String,
|
||||
val symbol: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class BillingTransaction(
|
||||
val id: String,
|
||||
val profileId: String,
|
||||
val amount: Double,
|
||||
val currency: String,
|
||||
val type: String,
|
||||
val status: String,
|
||||
val description: String,
|
||||
val createdAt: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class BillingSummary(
|
||||
val profileId: String,
|
||||
val period: String,
|
||||
val totalAmount: Double,
|
||||
val currency: String,
|
||||
val transactionCount: Int,
|
||||
val breakdown: Map<String, Double>
|
||||
)
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.telecom
|
||||
|
||||
/**
|
||||
* API for GraphQL queries
|
||||
*/
|
||||
class GraphQLAPI(private val client: HTTPClient) {
|
||||
|
||||
/**
|
||||
* Execute a GraphQL query
|
||||
*/
|
||||
suspend fun execute(query: String, variables: Map<String, Any>? = null): Map<String, Any> {
|
||||
val request = GraphQLRequest(query, variables)
|
||||
return client.post("/graphql", request)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.telecom
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Security API for fraud detection and SIM swap protection
|
||||
*/
|
||||
class SecurityAPI(private val httpClient: HTTPClient) {
|
||||
|
||||
/**
|
||||
* Analyze a transaction for fraud
|
||||
*/
|
||||
suspend fun analyzeTransaction(transaction: Map<String, Any>): FraudAlert? {
|
||||
return httpClient.post("/api/v1/security/fraud/analyze", transaction)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fraud alerts with filtering
|
||||
*/
|
||||
suspend fun getFraudAlerts(filter: FraudAlertFilter? = null): List<FraudAlert> {
|
||||
val payload = filter?.let {
|
||||
mapOf(
|
||||
"type" to it.type,
|
||||
"severity" to it.severity,
|
||||
"status" to it.status,
|
||||
"limit" to it.limit
|
||||
).filterValues { it != null }
|
||||
} ?: emptyMap()
|
||||
|
||||
return httpClient.post("/api/v1/security/fraud/alerts", payload)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update fraud alert status
|
||||
*/
|
||||
suspend fun updateAlertStatus(
|
||||
alertId: String,
|
||||
status: String,
|
||||
actions: List<String> = emptyList()
|
||||
): JsonObject {
|
||||
return httpClient.put("/api/v1/security/fraud/alerts/$alertId",
|
||||
mapOf(
|
||||
"status" to status,
|
||||
"actions" to actions
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fraud detection metrics
|
||||
*/
|
||||
suspend fun getFraudMetrics(period: String = "monthly"): FraudMetrics {
|
||||
return httpClient.get("/api/v1/security/fraud/metrics",
|
||||
mapOf("period" to period))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get detected fraud patterns
|
||||
*/
|
||||
suspend fun getFraudPatterns(): JsonObject {
|
||||
return httpClient.get("/api/v1/security/fraud/patterns")
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify SIM swap request
|
||||
*/
|
||||
suspend fun verifySIMSwap(profileId: String, msisdn: String): JsonObject {
|
||||
return httpClient.post("/api/v1/security/simswap/verify",
|
||||
mapOf(
|
||||
"profile_id" to profileId,
|
||||
"msisdn" to msisdn
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SIM swap history for a profile
|
||||
*/
|
||||
suspend fun getSIMSwapHistory(profileId: String): JsonObject {
|
||||
return httpClient.get("/api/v1/security/simswap/history/$profileId")
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class FraudAlert(
|
||||
val id: String,
|
||||
val type: String,
|
||||
val severity: String,
|
||||
val profileId: String,
|
||||
val description: String,
|
||||
val riskScore: Double,
|
||||
val evidence: List<String>,
|
||||
val ipAddress: String,
|
||||
val timestamp: String,
|
||||
val status: String,
|
||||
val actionsTaken: List<String>,
|
||||
val metadata: Map<String, Any>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class FraudMetrics(
|
||||
val period: String,
|
||||
val totalAlerts: Long,
|
||||
val resolvedAlerts: Long,
|
||||
val falsePositives: Long,
|
||||
val resolutionRate: Double,
|
||||
val falsePositiveRate: Double,
|
||||
val byType: Map<String, Long>,
|
||||
val bySeverity: Map<String, Long>,
|
||||
val generatedAt: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class FraudAlertFilter(
|
||||
val type: String? = null,
|
||||
val severity: String? = null,
|
||||
val status: String? = null,
|
||||
val limit: Int = 50
|
||||
)
|
||||
|
||||
@Serializable
|
||||
enum class FraudType(val value: String) {
|
||||
ACCOUNT_TAKEOVER("account_takeover"),
|
||||
SUBSCRIPTION_FRAUD("subscription_fraud"),
|
||||
PAYMENT_FRAUD("payment_fraud"),
|
||||
USAGE_ANOMALY("usage_anomaly"),
|
||||
SIM_SWAP("sim_swap")
|
||||
}
|
||||
|
||||
@Serializable
|
||||
enum class FraudSeverity(val value: String) {
|
||||
LOW("low"),
|
||||
MEDIUM("medium"),
|
||||
HIGH("high"),
|
||||
CRITICAL("critical")
|
||||
}
|
||||
@@ -17,7 +17,9 @@ class TelecomSDK private constructor(
|
||||
val payments: PaymentAPI
|
||||
val ratingPlans: RatingPlanAPI
|
||||
val system: SystemAPI
|
||||
val graphql: GraphQLAPI
|
||||
val analytics: AnalyticsAPI
|
||||
val security: SecurityAPI
|
||||
val currency: CurrencyAPI
|
||||
|
||||
companion object {
|
||||
/**
|
||||
@@ -33,9 +35,11 @@ class TelecomSDK private constructor(
|
||||
val payments = PaymentAPI(httpClient)
|
||||
val ratingPlans = RatingPlanAPI(httpClient)
|
||||
val system = SystemAPI(httpClient)
|
||||
val graphql = GraphQLAPI(httpClient)
|
||||
val analytics = AnalyticsAPI(httpClient)
|
||||
val security = SecurityAPI(httpClient)
|
||||
val currency = CurrencyAPI(httpClient)
|
||||
|
||||
return TelecomSDK(config, authProvider, httpClient, subscribers, usage, payments, ratingPlans, system, graphql)
|
||||
return TelecomSDK(config, authProvider, httpClient, subscribers, usage, payments, ratingPlans, system, analytics, security, currency)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +52,9 @@ class TelecomSDK private constructor(
|
||||
payments: PaymentAPI,
|
||||
ratingPlans: RatingPlanAPI,
|
||||
system: SystemAPI,
|
||||
graphql: GraphQLAPI
|
||||
analytics: AnalyticsAPI,
|
||||
security: SecurityAPI,
|
||||
currency: CurrencyAPI
|
||||
) {
|
||||
this.config = config
|
||||
this.authProvider = authProvider
|
||||
@@ -58,7 +64,9 @@ class TelecomSDK private constructor(
|
||||
this.payments = payments
|
||||
this.ratingPlans = ratingPlans
|
||||
this.system = system
|
||||
this.graphql = graphql
|
||||
this.analytics = analytics
|
||||
this.security = security
|
||||
this.currency = currency
|
||||
}
|
||||
|
||||
// Authentication methods
|
||||
|
||||
Reference in New Issue
Block a user