# Google Meet Configuration Module - Dependency Requirements

## Overview

This document outlines all dependencies required to integrate the Google Meet Configuration module into your SSHIA Laravel application. Follow these requirements carefully to ensure smooth installation and operation.

## System Requirements

### PHP Requirements
- **PHP Version:** 8.2 or 8.3
- **Extensions:**
  - `openssl` - For secure OAuth2 communication
  - `json` - For API response handling
  - `mbstring` - For string manipulation
  - `xml` - For XML parsing (Google API responses)
  - `curl` - For HTTP requests to Google APIs
  - `pdo` - For database operations
  - `pdo_mysql` - For MySQL database driver

### Database Requirements
- **MySQL:** 5.7 or 8.0
- **Character Set:** utf8mb4
- **Collation:** utf8mb4_unicode_ci

### Laravel Requirements
- **Laravel Version:** 12.x or higher
- **Laravel Extensions:**
  - `spatie/laravel-permission` (^6.24+) - Role and permission management

## Composer Dependencies

### Required Packages

Run the following commands to install:

```bash
# Core dependency
composer require spatie/laravel-permission:^6.24

# Google API Client (optional but for direct API communication)
composer require google/apiclient:^2.15

# Guzzle HTTP (alternative for API communication)
composer require guzzlehttp/guzzle:^7.8
```

### Package Descriptions

| Package | Version | Purpose | Required |
|---------|---------|---------|----------|
| `spatie/laravel-permission` | ^6.24 | Role and permission management | Yes |
| `google/apiclient` | ^1.15 | Official Google API client for PHP | No (alternative available) |
| `guzzlehttp/guzzle` | ^7.8 | HTTP client for API requests | No (alternative available) |

### Alternative HTTP Clients

We provide two alternatives for communicating with Google APIs:

#### Option 1: Guzzle HTTP (Recommended)
Guzzle HTTP is a modern, feature-rich HTTP client that widely used in the Laravel ecosystem.

```php
use GuzzleHttp\Client;

$client = new Client([
    'base_uri' => 'https://oauth2.googleapis.com/',
    'timeout' => 30,
]);

$response = $client->post('/token', [
    'form_params' => [
        'code' => $authorizationCode,
        'client_id' => $clientId,
        'client_secret' => $clientSecret,
        'redirect_uri' => $redirectUri,
        'grant_type' => 'authorization_code',
    ]
]);
```

#### Option 2: Laravel HTTP Client
```php
use Illuminate\Support\Facades\Http;

$response = Http::asForm()
    ->post('https://oauth2.googleapis.com/token', [
        'code' => $authorizationCode,
        'client_id' => $clientId,
        'client_secret' => $clientSecret,
        'redirect_uri' => $redirectUri,
        'grant_type' => 'authorization_code',
    ]);
```

## NPM Dependencies

### Required Frontend Packages

These packages enhance the user interface:

```json
{
    "dependencies": {
        "alpinejs": "^3.4.2",
        "tailwindcss": "^4.2.1",
        "flowbite": "^4.0.1",
        "@fortawesome/fontawesome-free": "^7.2.0"
    }
}
```

### Installing NPM Dependencies
```bash
npm install alpinejs tailwindcss flowbite @fortawesome/fontawesome-free
```

## Environment Variables

Add these variables to your `.env` file:

```env
# Google OAuth Configuration
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=https://your-domain.com/config/google-meet/callback

# Optional: Google Cloud Project ID
GOOGLE_PROJECT_ID=your-project-id
```

### Environment Variables Description

| Variable | Description | Required |
|----------|-------------|----------|
| `GOOGLE_CLIENT_ID` | OAuth2 Client ID from Google Cloud Console | Yes |
| `GOOGLE_CLIENT_SECRET` | OAuth2 Client Secret from Google Cloud Console | Yes |
| `GOOGLE_REDIRECT_URI` | OAuth2 callback URL | Yes |
| `GOOGLE_PROJECT_ID` | Google Cloud Project ID (optional) | No |

## Google Cloud Console Setup

### Required APIs

Enable the following APIs in your Google Cloud Project:

1. **Google Calendar API** - For creating and managing calendar events
   - Go to APIs & Services → Library
   - Search for "Google Calendar API"
   - Click "Enable"

### Required OAuth Scopes

Add these scopes to your OAuth consent screen configuration:

| Scope | Description |
|-------|-------------|
| `https://www.googleapis.com/auth/calendar.events` | Create and manage calendar events |
| `https://www.googleapis.com/auth/calendar` | Read access to calendars |
| `https://www.googleapis.com/auth/calendar.readonly` | Read-only calendar access (optional) |

### OAuth Consent Screen Configuration
1. Go to APIs & Services → OAuth consent screen
2. Configure the following:
   - User Type: Internal (recommended) or External
   - Application name: Your application name
   - Support email: Your support email
   - Scopes: Add the Calendar scopes mentioned above

### Credentials Setup
1. Go to APIs & Services → Credentials
2. Click "Create Credentials" → "OAuth client ID"
3. Configure:
   - Application type: Web application
   - Name: SSHIA Google Meet Integration
   - Authorized JavaScript origins: Your application domains
   - Authorized redirect URIs: 
     - `https://your-domain.com/config/google-meet/callback`
     - (Add any local development URLs if applicable)

## Installation Checklist

Follow these steps in order:

### 1. Install Composer Dependencies
```bash
composer install
```

### 2. Install NPM Dependencies
```bash
npm install
```

### 3. Run Database Migrations
```bash
php artisan migrate --path=/database/migrations/google-meet
```

### 4. Run Permission Seeder
```bash
php artisan db:seed --class=GoogleMeetPermissionSeeder
```

### 5. Configure Environment Variables
Add the required variables to your `.env` file

### 6. Set up Google Cloud Project
- Create a new project in Google Cloud Console
- Enable Google Calendar API
- Configure OAuth consent screen
- Create OAuth 2.0 credentials

### 7. Configure in Application
- Navigate to `/config/google-meet`
- Enter your OAuth credentials
- Save configuration
- Authenticate with Google

### 8. Test Integration
- Use the "Test Connection" feature
- Create a test meeting
- Verify logs are recorded

## Troubleshooting Common Issues

### Issue: "cURL error 60: SSL certificate problem"
**Solution:** Disable SSL verification in local development:
```php
// In your .env file for local development only
CURLOPT_SSL_VERIFICATION_PEER_ENABLED=false
```

### Issue: "Token expired"
**Solution:** The system automatically refreshes tokens. If issues persist:
- Re-authenticate with Google
- Check if refresh token is still valid

### Issue: "Permission denied"
**Solution:** 
- Ensure all required scopes are enabled
- Check OAuth consent screen configuration
- Verify user has Super Manager role

### Issue: "API not enabled"
**Solution:** 
- Go to Google Cloud Console
- Enable Google Calendar API
- Wait a few minutes for propagation

## Support and Resources

### Official Documentation
- [Google Calendar API Documentation](https://developers.google.com/calendar/api/v3/reference)
- [Google OAuth2 Documentation](https://developers.google.com/identity/protocols/oauth2)
- [Laravel Documentation](https://laravel.com/docs)
- [Spatie Permission Documentation](https://spatie.be/docs/laravel-permission)

### Internal Resources
- Configuration Dashboard: `/config/google-meet`
- Test Interface: `/config/google-meet/test`
- Activity Logs: `/config/google-meet/logs`
- Documentation: `/config/google-meet/documentation`

## Contact and Support

For technical support or questions about this module:
1. Check the documentation first
2. Review the activity logs for error details
3. Consult with your system administrator
4. Submit a support ticket through your internal support system
