<?php

namespace App\Services;

use Illuminate\Support\Facades\Log;

class SmsService
{
    /**
     * Send SMS
     */
    public function send($phone, $message)
    {
        try {
            // Your SMS gateway integration here
            // Example: 
            // $this->sendViaGateway($phone, $message);
            
            Log::info('SMS sent to ' . $phone . ': ' . $message);
            
            return [
                'success' => true,
                'message' => 'SMS sent successfully'
            ];
            
        } catch (\Exception $e) {
            Log::error('SMS sending failed: ' . $e->getMessage());
            
            return [
                'success' => false,
                'message' => 'SMS sending failed: ' . $e->getMessage()
            ];
        }
    }

    /**
     * Send installment reminder SMS
     */
    public function sendInstallmentReminder($customer, $installment)
    {
        $message = "Dear {$customer->name}, your installment of ৳ {$installment->amount} is due on {$installment->due_date}. Please pay on time to avoid late fees. - Walton Plaza";
        
        return $this->send($customer->phone, $message);
    }

    /**
     * Send payment confirmation SMS
     */
    public function sendPaymentConfirmation($customer, $payment)
    {
        $message = "Dear {$customer->name}, thank you for your payment of ৳ {$payment->amount}. Your outstanding balance is ৳ {$payment->sale->due_amount}. - Walton Plaza";
        
        return $this->send($customer->phone, $message);
    }

    /**
     * Send welcome SMS
     */
    public function sendWelcomeSms($customer)
    {
        $message = "Welcome {$customer->name} to Walton Plaza! Thank you for being our valued customer.";
        
        return $this->send($customer->phone, $message);
    }
}