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';

/**
 * OPPO Push provider.
 *
 * Production integration:
 *   OPPO Push HTTP API (https://open.oppomobile.com/new/developmentDoc/info?id=11224)
 *   Environment: OPPO_APP_KEY, OPPO_MASTER_SECRET
 *
 * Required for OPPO/OnePlus/Realme devices in China.
 */
@Injectable()
export class OppoPushProvider implements IPushChannelProvider {
  private readonly logger = new Logger(OppoPushProvider.name);
  readonly channel = PushChannel.OPPO;

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

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