# Call Module — Function-by-Function Documentation

## Overview
The `src/call/` module implements one-to-one and group calls using Agora. It provides:
- REST APIs to initiate a call and update its status
- A Socket.IO gateway to orchestrate the live call lifecycle (accept/decline/not-answered/end, join/leave)
- Push notifications to iOS (VOIP) and Android (FCM)

## Module Structure
- **Module**: `src/call/call.module.ts`
- **Controller**: `src/call/call.controller.ts`
- **Service**: `src/call/call.service.ts`
- **Gateway**: `src/call/call.gateway.ts`
- **DTOs**: `src/call/dto/call.dto.ts`
- **Schemas**: `src/call/schema/calling.schema.ts`, `src/call/schema/call.joined.schema.ts`

## Enums
- `CallMode`: `AUDIO | VIDEO`
- `CallType`: `ONE_TO_ONE | GROUP`
- `CallingStatus`: `PENDING | ACCEPT | DECLINE | NOT_ANSWERE | END`
- `AgoraRole`: `PUBLISHER | SUBSCRIBER`

## Environment Variables
- `AGORA_APP_ID`: Agora App ID
- `AGORA_APP_CERTIFICATE`: Agora App Certificate
- `AGORA_TOKEN_EXPIRATION`: Token expiration time (default: 18000s)

## Dependencies
- `agora-token`
- `moment`
- `mongoose`
- `@nestjs/websockets`
- `socket.io`

## Module: `call.module.ts`
### Imports:
- `AuthModule`
- `CommonModule`
- `ModelsModule`

### Controllers:
- `CallController`

### Providers:
- `CallService`
- `CallGateway`

## Controller: `call.controller.ts`
### `makeCall(@Body dto: MakeCallDto, @Request req)`
- **Route**: POST `/call/make`
- **Guards**: `AuthGuard` + bearer auth
- **Description**: Initiates a new call
- **Returns**: 
  ```json
  {
    "success": true,
    "message": "Token has been successfully generated",
    "data": {
      "call_id": "string",
      "channel_name": "string",
      "agora_token": "string"
    }
  }
  ```

### `updateCallStatus(@Body dto: UpdateCallStatusApiDto, @Request req)`
- **Route**: POST `/call/update-call-status`
- **Guards**: `AuthGuard` + `@Public()`
- **Description**: Updates the status of an ongoing call
- **Returns**:
  ```json
  {
    "success": true,
    "message": "Call status has been successfully updated",
    "data": {}
  }
  ```

## Service: `call.service.ts`
### `constructor()`
- **Dependencies**:
  - `ConfigService`
  - `ModelsService`
  - `CommonService`

### `makeCall(user: any, makeCallDto: MakeCallDto)`
- **Description**: Creates a new call and generates Agora token
- **Parameters**:
  - `user`: User object from request
  - `makeCallDto`: MakeCallDto containing call details
- **Returns**: Call details with Agora token

### `updateCallStatus(updateCallStatusDto: UpdateCallStatusDto)`
- **Description**: Updates the status of a call
- **Parameters**:
  - `updateCa
  
  
  llStatusDto`: UpdateCallStatusDto with new status
- **Returns**: Updated call document
