import { Injectable} from "@nestjs/common";
import { NotificationStrategy } from "./notification.strategy";
import { HttpService } from '@nestjs/axios';
import { ConfigService } from "@nestjs/config";
import {  firstValueFrom } from 'rxjs';

@Injectable()
export class SmsNotificationStrategy implements NotificationStrategy {
    constructor(private readonly httpService: HttpService, private readonly configService: ConfigService) { }
    async send(recipient: string, message: string) {
        const url = this.configService.get("OZIKING_SMS_URL")
        const body = {
            to: recipient,
            text: message
        }
        const response = await firstValueFrom(
            this.httpService.post(
                url,
                body,
            ),
        );

        return response.status === 201;
    }
}
