# FiveManage CDN Integration Documentation

## Overview
This document explains the implementation of FiveManage CDN integration for image uploads in the government services platform.

## Components

### 1. Configuration (`config/fivemanage.php`)
- API token configuration via environment variables
- Base URL and endpoint settings
- File validation rules (extensions, size limits)
- Timeout and retry settings

### 2. Service Layer (`App\Services\FiveManageUploadService`)
- Handles file validation before upload
- Manages API communication with FiveManage CDN
- Implements retry logic for failed uploads
- Provides methods for both upload and delete operations
- Includes comprehensive logging for debugging

### 3. Model Updates (`App\Models\UserGov`)
- Added `photo_profile` and `signature` to fillable attributes
- Proper casting and validation for the new fields

### 4. Controller Integration (`App\Http\Controllers\ProfileController`)
- Updated to handle file uploads to CDN instead of local storage
- Processes both photo profile uploads and signature image uploads
- Implements proper error handling and user feedback
- Uses the FiveManageUploadService for all CDN operations

### 5. Request Validation (`App\Http\Requests\ProfileUpdateRequest`)
- Added validation rules for image uploads
- Specific validation for both photo and signature image formats
- Proper error messages in Indonesian

## Usage Flow

### Photo Profile Upload
1. User selects an image file in the profile form
2. Frontend validates file type and size
3. Form submits to ProfileController
4. Controller validates file using FormRequest
5. Controller uses FiveManageUploadService to upload to CDN
6. CDN URL is saved to `photo_profile` field in database
7. Success/error feedback is provided to user

### Signature Upload
1. User selects an image file for signature in the profile form
2. Frontend validates file type and size
3. Form submits to ProfileController with `signature_upload` field
4. Controller validates file using FormRequest
5. Controller uses FiveManageUploadService to upload to CDN
6. CDN URL is saved to `signature` field in database
7. Success/error feedback is provided to user

## Error Handling
- Network failures trigger retry logic (default 3 attempts)
- File validation occurs both client-side and server-side
- Comprehensive logging for debugging
- Graceful error messages to users
- Fallback mechanisms for CDN failures

## Security Considerations
- API tokens stored in environment variables
- File validation prevents malicious uploads
- Proper authentication through Laravel's auth system
- Temporary files are securely handled and cleaned up

## Environment Variables
```
FIVEMANAGE_API_TOKEN=your_api_token_here
FIVEMANAGE_BASE_URL=https://api.fivemanage.com
FIVEMANAGE_UPLOAD_ENDPOINT=/upload
```