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

/**
 * Xiaomi (Mi Push) provider.
 *
 * Production integration:
 *   Mi Push HTTP API (https://dev.mi.com/console/doc/detail?pId=1163)
 *   Environment: XIAOMI_APP_SECRET, XIAOMI_PACKAGE_NAME
 *
 * Required for Xiaomi/Redmi/POCO devices in China.
 */
@Injectable()
export class XiaomiPushProvider implements IPushChannelProvider {
  private readonly logger = new Logger(XiaomiPushProvider.name);
  readonly channel = PushChannel.XIAOMI;

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

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