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

/**
 * vivo Push provider.
 *
 * Production integration:
 *   vivo Push HTTP API (https://dev.vivo.com.cn/documentCenter/doc/362)
 *   Environment: VIVO_APP_ID, VIVO_APP_KEY, VIVO_APP_SECRET
 *
 * Required for vivo/iQOO devices in China.
 */
@Injectable()
export class VivoPushProvider implements IPushChannelProvider {
  private readonly logger = new Logger(VivoPushProvider.name);
  readonly channel = PushChannel.VIVO;

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

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