<?php

namespace App\Modules\SMS;

use App\Modules\Makeable;
use App\Modules\ModuleContract;
use App\Modules\SMS\Repositories\SMSRepository;

class SMSModule implements ModuleContract
{
    use Makeable;

    /**
     * Module is enabled
     */
    protected bool $enabled = true;

    /**
     * Check if is module enabled
     */
    public function isEnabled(): bool
    {
        return $this->enabled;
    }

    /**
     * Disable module
     */
    public function disable(): void
    {
        $this->enabled = false;
    }

    /**
     * Enable module
     */
    public function enable(): void
    {
        $this->enabled = true;
    }

    /**
     * Check if module has a filament resource
     */
    public function hasFilamentResource(): bool
    {
        return true;
    }

    /**
     * Send a sms
     */
    public function send(...$args)
    {
        return SMSRepository::sendSMS(...$args);
    }

    /**
     * Send a sms verification
     */
    public function verify(...$args)
    {
        if (class_exists('App\Modules\OTPVerification\Repositories\OTPVerificationRepository') && module('OTPVerification')->isEnabled()) {
            $OTPVerificationRepository = 'App\Modules\OTPVerification\Repositories\OTPVerificationRepository';

            return $OTPVerificationRepository::sendSMSVerification(...$args);
        }

        if (app()->environment('local')) {
            throw new \Exception('OTPVerification module is not enabled');
        }

        return false;
    }
}
