<?php

namespace App\Actions\Tenancy\Visit;

use App\Models\City;
use App\Models\Clinic;
use App\Models\Doctor;
use App\Models\Tenancy\Sms;
use Illuminate\Support\Carbon;

class SendCreateVisitSmsAction
{
    public function execute(
        Clinic $clinic,
        City   $city,
        Doctor $doctor,
        Carbon $startDate,
        ?bool  $isAlien,
        string $phone,
        string $url = null
    ): void
    {
        $domain = $url ?: 'https://' . $clinic->client_unique_name . '.cosmetiq.ge';
        if ($isAlien) {
            $address = $city->name_en . ', ' . $clinic->address_en;
            $message = 'Visit is booked on ' . $startDate->toDateTimeString() . ',  Doctor - ' . $doctor->name . ' '
                . $doctor->lastname . '. Addr: ' . $address . ', T: ' . $clinic->phone . ', Clinic: '
                . $clinic->organization_en . '. ' . $domain;
        } else {
            $address = $city->name . ', ' . $clinic->address;
            $message = 'ვიზიტი დაჯავშნილია ' . $startDate->toDateTimeString() . ',  ექიმი - ' . $doctor->name . ' ' . $doctor->lastname . '. მის: ' . $address . ', T: ' . $clinic->phone . ', კლინიკა ' . $clinic->organization . '. ' . $domain;
        }

        $smsSender = Sms::TYPES['wsdl'];
        if ($smsSender == 1) {
            $smsUser = $clinic->sms_user;
        } else {
            $smsUser = $clinic->sms_bulk_user;
        }
        Sms::send(Sms::TYPES['gosms'], $phone, $message, 'add_visit', $smsUser, $clinic->sms_pass);
    }
}
