import { Injectable, Logger } from '@nestjs/common';
import { PushChannel } from '../../../domain/entities/device-token.entity';
import {
  IPushChannelProvider,
  PushPayload,
  PushResult,
} from '../../../domain/ports/push-channel-provider.interface';

/**
 * Huawei Mobile Services (HMS) Push Kit provider.
 *
 * Production integration:
 *   HMS Push Kit REST API (https://developer.huawei.com/consumer/en/hms/huawei-pushkit)
 *   Environment: HMS_APP_ID, HMS_APP_SECRET, HMS_TOKEN_URL, HMS_PUSH_URL
 *
 * Required for Huawei devices in China (no Google Play Services).
 */
@Injectable()
export class HmsPushProvider implements IPushChannelProvider {
  private readonly logger = new Logger(HmsPushProvider.name);
  readonly channel = PushChannel.HMS;

  async send(payload: PushPayload): Promise<PushResult> {
    // TODO: Replace with HMS Push Kit REST API call
    this.logger.log(
      `[MOCK HMS] → token=${payload.token.slice(0, 12)}… title="${payload.title}"`,
    );
    return {
      success: true,
      messageId: `hms-mock-${Date.now()}`,
    };
  }

  async sendBatch(payloads: PushPayload[]): Promise<PushResult[]> {
    // TODO: Replace with HMS batch push
    this.logger.log(`[MOCK HMS] Batch send: ${payloads.length} messages`);
    return payloads.map((p) => ({
      success: true,
      messageId: `hms-mock-${Date.now()}-${p.token.slice(0, 8)}`,
    }));
  }
}
