2025-09-25 15:11:28 +09:00
|
|
|
import { Injectable } from "@nestjs/common";
|
|
|
|
|
import { SimOrchestratorService } from "./sim-management/services/sim-orchestrator.service";
|
|
|
|
|
import { SimNotificationService } from "./sim-management/services/sim-notification.service";
|
2025-11-21 18:41:14 +09:00
|
|
|
import type {
|
|
|
|
|
SimDetails,
|
|
|
|
|
SimUsage,
|
|
|
|
|
SimTopUpHistory,
|
|
|
|
|
} from "@bff/integrations/freebit/interfaces/freebit.types";
|
2025-09-25 15:11:28 +09:00
|
|
|
import type {
|
|
|
|
|
SimTopUpRequest,
|
|
|
|
|
SimPlanChangeRequest,
|
|
|
|
|
SimCancelRequest,
|
|
|
|
|
SimTopUpHistoryRequest,
|
|
|
|
|
SimFeaturesUpdateRequest,
|
2025-11-21 18:41:14 +09:00
|
|
|
} from "./sim-management/types/sim-requests.types";
|
2025-09-25 18:59:07 +09:00
|
|
|
import type { SimNotificationContext } from "./sim-management/interfaces/sim-base.interface";
|
2025-09-04 18:34:28 +09:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class SimManagementService {
|
|
|
|
|
constructor(
|
2025-09-25 15:11:28 +09:00
|
|
|
private readonly simOrchestrator: SimOrchestratorService,
|
|
|
|
|
private readonly simNotification: SimNotificationService
|
2025-09-04 18:34:28 +09:00
|
|
|
) {}
|
|
|
|
|
|
2025-09-25 15:11:28 +09:00
|
|
|
// Delegate to notification service for backward compatibility
|
2025-09-10 16:33:24 +09:00
|
|
|
private async notifySimAction(
|
|
|
|
|
action: string,
|
|
|
|
|
status: "SUCCESS" | "ERROR",
|
2025-09-25 18:59:07 +09:00
|
|
|
context: SimNotificationContext
|
2025-09-10 16:33:24 +09:00
|
|
|
): Promise<void> {
|
2025-09-25 18:59:07 +09:00
|
|
|
return this.simNotification.notifySimAction(action, status, context);
|
2025-09-10 16:33:24 +09:00
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:34:28 +09:00
|
|
|
/**
|
|
|
|
|
* Debug method to check subscription data for SIM services
|
|
|
|
|
*/
|
2025-09-09 15:59:30 +09:00
|
|
|
async debugSimSubscription(
|
|
|
|
|
userId: string,
|
|
|
|
|
subscriptionId: number
|
|
|
|
|
): Promise<Record<string, unknown>> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.debugSimSubscription(userId, subscriptionId);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
|
|
|
|
|
2025-11-21 18:41:14 +09:00
|
|
|
/**
|
|
|
|
|
* Debug method to query Freebit directly for any account's details
|
|
|
|
|
*/
|
|
|
|
|
async getSimDetailsDebug(account: string): Promise<SimDetails> {
|
|
|
|
|
return this.simOrchestrator.getSimDetailsDirectly(account);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-25 15:11:28 +09:00
|
|
|
// This method is now handled by SimValidationService internally
|
2025-09-04 18:34:28 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SIM details for a subscription
|
|
|
|
|
*/
|
|
|
|
|
async getSimDetails(userId: string, subscriptionId: number): Promise<SimDetails> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.getSimDetails(userId, subscriptionId);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SIM data usage for a subscription
|
|
|
|
|
*/
|
|
|
|
|
async getSimUsage(userId: string, subscriptionId: number): Promise<SimUsage> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.getSimUsage(userId, subscriptionId);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-06 13:57:18 +09:00
|
|
|
* Top up SIM data quota with payment processing
|
|
|
|
|
* Pricing: 1GB = 500 JPY
|
2025-09-04 18:34:28 +09:00
|
|
|
*/
|
|
|
|
|
async topUpSim(userId: string, subscriptionId: number, request: SimTopUpRequest): Promise<void> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.topUpSim(userId, subscriptionId, request);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SIM top-up history
|
|
|
|
|
*/
|
|
|
|
|
async getSimTopUpHistory(
|
2025-09-09 15:45:03 +09:00
|
|
|
userId: string,
|
|
|
|
|
subscriptionId: number,
|
2025-09-04 18:34:28 +09:00
|
|
|
request: SimTopUpHistoryRequest
|
2025-11-21 18:41:14 +09:00
|
|
|
// @ts-ignore - ignoring mismatch for now as we are migrating
|
2025-09-04 18:34:28 +09:00
|
|
|
): Promise<SimTopUpHistory> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.getSimTopUpHistory(userId, subscriptionId, request);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Change SIM plan
|
|
|
|
|
*/
|
|
|
|
|
async changeSimPlan(
|
2025-09-09 15:45:03 +09:00
|
|
|
userId: string,
|
|
|
|
|
subscriptionId: number,
|
2025-09-04 18:34:28 +09:00
|
|
|
request: SimPlanChangeRequest
|
|
|
|
|
): Promise<{ ipv4?: string; ipv6?: string }> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.changeSimPlan(userId, subscriptionId, request);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
|
|
|
|
|
2025-09-05 15:39:43 +09:00
|
|
|
/**
|
|
|
|
|
* Update SIM features (voicemail, call waiting, roaming, network type)
|
|
|
|
|
*/
|
|
|
|
|
async updateSimFeatures(
|
|
|
|
|
userId: string,
|
|
|
|
|
subscriptionId: number,
|
|
|
|
|
request: SimFeaturesUpdateRequest
|
|
|
|
|
): Promise<void> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.updateSimFeatures(userId, subscriptionId, request);
|
2025-09-05 15:39:43 +09:00
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:34:28 +09:00
|
|
|
/**
|
|
|
|
|
* Cancel SIM service
|
|
|
|
|
*/
|
2025-09-09 15:45:03 +09:00
|
|
|
async cancelSim(
|
|
|
|
|
userId: string,
|
|
|
|
|
subscriptionId: number,
|
|
|
|
|
request: SimCancelRequest = {}
|
|
|
|
|
): Promise<void> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.cancelSim(userId, subscriptionId, request);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reissue eSIM profile
|
|
|
|
|
*/
|
2025-11-21 18:41:14 +09:00
|
|
|
async reissueEsimProfile(userId: string, subscriptionId: number, newEid?: string): Promise<void> {
|
|
|
|
|
return this.simOrchestrator.reissueEsimProfile(userId, subscriptionId, newEid);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get comprehensive SIM information (details + usage combined)
|
|
|
|
|
*/
|
2025-11-21 18:41:14 +09:00
|
|
|
async getSimInfo(
|
|
|
|
|
userId: string,
|
|
|
|
|
subscriptionId: number
|
|
|
|
|
): Promise<{
|
|
|
|
|
details: SimDetails;
|
|
|
|
|
usage: SimUsage;
|
|
|
|
|
}> {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simOrchestrator.getSimInfo(userId, subscriptionId);
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|
2025-09-08 18:31:26 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert technical errors to user-friendly messages for SIM operations
|
|
|
|
|
*/
|
|
|
|
|
private getUserFriendlySimError(technicalError: string): string {
|
2025-09-25 15:11:28 +09:00
|
|
|
return this.simNotification.getUserFriendlySimError(technicalError);
|
2025-09-08 18:31:26 +09:00
|
|
|
}
|
2025-09-04 18:34:28 +09:00
|
|
|
}
|