# Networking Functionality API Guide

## 🎯 Comment implémenter chaque fonctionnalité

### 1. **Favoriser un profil** 
```javascript
// Toggle favorite status
POST /api/v1/networking/{networking_id}/toggle-favorite

// Response
{
  "networking": {...},
  "message": "Added to favorites" // or "Removed from favorites"
}

// Get favorite connections
GET /api/v1/networking/my/favorites
```

### 2. **Envoyer un message (chat)**
```javascript
// Create a chat networking request
POST /api/v1/networking
{
  "receiver_id": 123,
  "subject": "Discussion about water management",
  "message": "Hello, I'd like to discuss...",
  "type": "chat"
}

// Send message in existing chat
POST /api/v1/chat/{networking_id}/send
{
  "message": "Your message here",
  "attachments": ["file1.pdf", "image1.jpg"] // optional
}

// Get chat conversations
GET /api/v1/chat/conversations

// Get messages for a specific conversation
GET /api/v1/chat/{networking_id}/messages
```

### 3. **Envoyer une demande de réunion**
```javascript
// Create meeting request
POST /api/v1/networking
{
  "receiver_id": 123,
  "subject": "Meeting Request - Water Innovation",
  "message": "I would like to schedule a meeting...",
  "type": "meeting",
  "duration_meeting": 60, // minutes
  "location": "Conference Room A",
  "date_of_meeting": "2025-08-10 14:00:00"
}

// Accept meeting request (Receiver only)
POST /api/v1/networking/{networking_id}/accept

// Status flow: pending → accepted → completed
```

### 4. **Gestion des statuts**
```javascript
// Get pending requests (for receiver)
GET /api/v1/networking/my/pending

// Accept request
POST /api/v1/networking/{networking_id}/accept

// Reject request
POST /api/v1/networking/{networking_id}/reject
{
  "rejection_reason": "Not available at that time"
}

// Complete meeting
POST /api/v1/networking/{networking_id}/complete

// Cancel request
POST /api/v1/networking/{networking_id}/cancel
```

### 5. **Pour les sociétés (Exposants)**
```javascript
// Create networking with preferred contact
POST /api/v1/networking
{
  "receiver_id": 123,
  "subject": "Business Partnership",
  "message": "We would like to discuss...",
  "type": "meeting",
  "preferred_contact": {
    "name": "John Doe",
    "email": "contact@company.com",
    "phone": "+1234567890",
    "position": "Business Development Manager"
  }
}
```

## 📱 Frontend Implementation Examples

### Chat Interface
```javascript
// Get conversations
const conversations = await fetch('/api/v1/chat/conversations');

// Display unread count
const unreadCount = await fetch('/api/v1/chat/unread-count');

// Send message
const sendMessage = async (networkingId, message) => {
  return await fetch(`/api/v1/chat/${networkingId}/send`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ message })
  });
};
```

### Meeting Requests
```javascript
// Create meeting request
const createMeeting = async (receiverId, subject, message, dateTime) => {
  return await fetch('/api/v1/networking', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      receiver_id: receiverId,
      subject,
      message,
      type: 'meeting',
      date_of_meeting: dateTime,
      duration_meeting: 60,
      location: 'Conference Room'
    })
  });
};

// Accept meeting
const acceptMeeting = async (networkingId) => {
  return await fetch(`/api/v1/networking/${networkingId}/accept`, {
    method: 'POST'
  });
};
```

### Favorites Management
```javascript
// Toggle favorite
const toggleFavorite = async (networkingId) => {
  return await fetch(`/api/v1/networking/${networkingId}/toggle-favorite`, {
    method: 'POST'
  });
};

// Get favorites
const getFavorites = async () => {
  return await fetch('/api/v1/networking/my/favorites');
};
```

## 🗂️ Database Structure

### `networkings` table
- Stores networking requests (chat or meeting)
- Tracks status, favorites, preferred contacts
- Links requester and receiver

### `networking_messages` table
- Stores chat messages
- Tracks read status
- Supports attachments

## 📊 Status Flow

1. **Pending** (initial state)
2. **Accepted** (receiver accepts)
3. **Completed** (meeting finished)
4. **Rejected** (receiver declines)
5. **Cancelled** (either party cancels)

## 🔔 Real-time Features (Optional)

Pour implémenter en temps réel:
- WebSockets pour les messages instantanés
- Pusher/Laravel Echo pour les notifications
- Real-time status updates

## 📝 Migration Commands

```bash
# Run migrations
php artisan migrate

# Seed sample data
php artisan db:seed

# Or seed specific seeder
php artisan db:seed --class=NetworkingSeeder
```
