# Conflict Review Timeout System - Installation Instructions

## Quick Setup

### 1. Add Environment Variable

Add this line to your `.env` file:

```env
# Conflict review timeout in working hours (excluding weekends)
CONFLICT_REVIEW_TIMEOUT_HOURS=48
```

### 2. Test the System

Run a dry-run test to ensure everything is working:

```bash
php artisan conflict-reviews:process-expired --dry-run
```

You should see output like:
```
🔄 Processing expired conflict reviews...
⚠️  DRY RUN MODE - No reviews will be updated
⏰ Timeout configured for: 48 working hours (excluding weekends)
✅ No expired conflict reviews found
```

### 3. Configure Cron Job (Production Only)

The system automatically schedules the command via Laravel's task scheduler. Ensure you have the Laravel scheduler running in your cron:

```bash
# Add this to your crontab (crontab -e)
* * * * * cd /path/to/your/project && php artisan schedule:run >> /dev/null 2>&1
```

## What Gets Installed

### Files Created/Modified:

1. **Modified**: `app/Models/ConflictReview.php`
   - Added `isExpired()` method
   - Added `markAsNoConflictDueToTimeout()` method

2. **Created**: `app/Console/Commands/ProcessExpiredConflictReviews.php`
   - New console command to process expired reviews

3. **Modified**: `app/Console/Kernel.php`
   - Added scheduled task to run hourly during business hours

4. **Created**: `docs/CONFLICT_REVIEW_TIMEOUT_SYSTEM.md`
   - Complete documentation of the system

## How It Works

- **Automatically runs**: Every hour, Monday-Friday, 8 AM - 6 PM
- **Excludes weekends**: Only working days count toward timeout
- **Configurable timeout**: Set via `CONFLICT_REVIEW_TIMEOUT_HOURS` env variable
- **Safe processing**: Uses overlapping protection and comprehensive logging
- **Audit trail**: All changes logged with timestamps and reasons

## Default Configuration

- **Timeout**: 48 working hours (2 business days)
- **Schedule**: Hourly during business hours, weekdays only
- **Status change**: `pending` → `no_conflict` (English: "no objection")
- **Notes**: Automatic note added explaining the timeout

## Testing

You can test different scenarios:

```bash
# Test current configuration
php artisan conflict-reviews:process-expired --dry-run

# Test with different timeout (temporarily change .env)
# Then run the dry-run command again
```

## Monitoring

Check the log file for processing activity:
```bash
tail -f storage/logs/conflict-reviews-timeout.log
```

The system is now ready to use! It will automatically process expired conflict reviews according to your configured timeout hours.