<?php

namespace App\Notifications;

use App\Helpers\SmsHelper;

class SmsNotification
{
    /**
     * Send new message notification to admin
     */
    public static function newMessage(string $name, string $email, string $phone): void
    {
        $adminPhone = config('app.admin_phone');
        
        \Illuminate\Support\Facades\Log::info('SmsNotification::newMessage called', [
            'admin_phone' => $adminPhone,
            'contact_name' => $name,
            'contact_email' => $email,
            'contact_phone' => $phone,
        ]);
        
        if ($adminPhone) {
            $message = "New contact message from {$name}. Email: {$email}, Phone: {$phone}. Check admin panel for details.";
            
            \Illuminate\Support\Facades\Log::info('Sending SMS', [
                'to' => $adminPhone,
                'message' => $message,
            ]);
            
            $result = SmsHelper::send($adminPhone, $message);
            
            \Illuminate\Support\Facades\Log::info('SMS send result', $result);
        } else {
            \Illuminate\Support\Facades\Log::warning('Admin phone not configured, skipping SMS notification');
        }
    }

    /**
     * Send new service inquiry notification
     */
    public static function newServiceInquiry(string $serviceName, string $clientName, string $clientPhone): void
    {
        $adminPhone = config('app.admin_phone');
        
        if ($adminPhone) {
            $message = "New inquiry for: {$serviceName}\nFrom: {$clientName}\nPhone: {$clientPhone}";
            SmsHelper::send($adminPhone, $message);
        }
    }

    /**
     * Send new subscriber notification to admin
     */
    public static function newSubscriber(string $email): void
    {
        $adminPhone = config('app.admin_phone');
        
        \Illuminate\Support\Facades\Log::info('SmsNotification::newSubscriber called', [
            'admin_phone' => $adminPhone,
            'subscriber_email' => $email,
        ]);
        
        if ($adminPhone) {
            $message = "New newsletter subscriber: {$email}. Check admin panel for details.";
            
            \Illuminate\Support\Facades\Log::info('Sending SMS', [
                'to' => $adminPhone,
                'message' => $message,
            ]);
            
            $result = SmsHelper::send($adminPhone, $message);
            
            \Illuminate\Support\Facades\Log::info('SMS send result', $result);
        } else {
            \Illuminate\Support\Facades\Log::warning('Admin phone not configured, skipping SMS notification');
        }
    }

    /**
     * Send welcome SMS to new subscriber
     */
    public static function welcomeSubscriber(string $phone): void
    {
        $companyName = config('app.name');
        $message = "Welcome to {$companyName}! Thank you for subscribing to our newsletter.";
        SmsHelper::send($phone, $message);
    }

    /**
     * Send custom SMS notification
     */
    public static function custom(string $phone, string $message): array
    {
        return SmsHelper::send($phone, $message);
    }

    /**
     * Send bulk SMS notification
     */
    public static function bulk(array $phones, string $message): array
    {
        return SmsHelper::sendBulk($phones, $message);
    }
}
