# CSV Import Field Mapping

This document shows how CSV columns map to Post model fields.

## Required Fields

| CSV Column | Post Field | Notes |
|------------|------------|-------|
| `title` or `casino_name` | `title` | Uses `casino_name` if `title` is empty |
| - | `slug` | Auto-generated from title, **always ends with "-review"** |
| `body` | `body` | Default: `<p>Content will be added here.</p>` |
| - | `user_id` | From "Default Author" selection |
| `active` | `active` | Boolean, default: false (unless auto-publish) |
| `published_at` | `published_at` | DateTime, default: null (unless auto-publish) |

## Optional Fields (Auto-mapped)

| CSV Column | Post Field | Type | Notes |
|------------|------------|------|-------|
| `thumbnail` | `thumbnail` | string | Image path |
| `local_image_path` | `thumbnail` | string | **Auto-uploads from scraped_data/images/** |
| `meta_title` | `meta_title` | string | SEO meta title |
| `meta_description` | `meta_description` | string | SEO meta description |
| `badge` | `badge` | string | Badge text |
| `rating` | `rating` | float | **Multiplied by 2** (5-point → 10-point scale) |
| `short_description` | `short_description` | string | Short description |
| `casino_url` | `casino_url` | string | Casino website URL |
| `founded_year` | `founded_year` | integer | Year (1900-current) |
| `min_deposit` | `min_deposit` | JSON | **Random value if missing**: 50-500 NOK |
| `max_withdrawal` | `max_withdrawal` | JSON | **Random value if missing**: 5,000-100,000 NOK |
| `casino_rtp` | `casino_rtp` | float | **Random value if missing**: 94.0-98.0 |
| `payment_methods` | `payment_methods` | JSON array | Comma-separated or JSON |
| `game_providers` | `game_providers` | JSON array | Comma-separated or JSON |
| `languages` | `languages` | JSON array | **Default: ["no"]** if missing |
| `language` | `languages` | JSON array | Single language → converted to array |
| `casino_type` | `casino_type` | JSON array | e.g., ["crypto_casino"] |
| `welcome_bonus` | `welcome_bonus` | JSON object | Complex structure |
| `bonus_text` | `welcome_bonus` | JSON object | **Auto-creates welcome_bonus structure** |
| `casino_operator` | `casino_operator` | string | Operator name |
| `licenses` | `licenses` | JSON array | e.g., ["Curacao"] |
| `casino_features` | `casino_features` | JSON array | e.g., ["mobile_casino", "live_dealer"] |
| `bonus_types` | `bonus_types` | JSON array | e.g., ["welcome_bonus", "free_spins"] |
| `sportsbook_types` | `sportsbook_types` | JSON array | e.g., ["football", "basketball"] |
| `kyc_required` | `kyc_required` | string | e.g., "after_limit" |
| `customer_support_email` | `customer_support_email` | string | Email address |
| `avg_response_time` | `avg_response_time` | string | e.g., "~ 24 hours" |
| `footer_disclaimer` | `footer_disclaimer` | string | Footer disclaimer text |
| `include_in_top_3` | `include_in_top_3` | integer | Top 3 position |
| `review_block` | `review_block` | JSON | Review block data |
| `trust_score_data` | `trust_score_data` | JSON | Trust score data |

## Special Handling

### 1. Slug Generation
- Always ends with `-review`
- Example: `cazimbo-casino` → `cazimbo-casino-review`
- If slug already has `-review`, it's removed and re-added

### 2. Languages
- **Always an array**: `["no"]` or `["en", "de"]`
- Default: `["no"]` if not specified
- Supports:
  - Single value: `language: "no"` → `["no"]`
  - Comma-separated: `language: "no,en"` → `["no", "en"]`
  - JSON array: `languages: ["no", "en"]` → `["no", "en"]`

### 3. Rating
- **Multiplied by 2** (CSV uses 5-point, system uses 10-point)
- Example: CSV `4.5` → Database `9.0`
- Capped at 10.0

### 4. Welcome Bonus
- Structure: `{"bonus_text": {"no": "100% up to 5000 NOK"}}`
- If `bonus_text` column exists, creates structure for all languages
- Example: `bonus_text: "100% up to 5000 NOK"` + `language: "no"` → 
  ```json
  {
    "bonus_text": {
      "no": "100% up to 5000 NOK"
    }
  }
  ```

### 5. Image Upload
- Reads `local_image_path` column (e.g., `images/winota_casino.png`)
- Looks in: `scraped_data/images/`
- Copies to: `storage/app/public/post-thumbnails/`
- Auto-generates filename: `{casino-name}_{timestamp}.{ext}`

### 6. Random Values (if missing)
- `min_deposit`: Random from [50, 100, 150, 200, 250, 300, 500] NOK
- `max_withdrawal`: Random from ['5,000', '10,000', '20,000', '50,000', '100,000'] NOK
- `casino_rtp`: Random between 94.0 and 98.0

## Chipy CSV Format Support

The importer supports both formats:

### AskGamblers Format
- `title` column
- `body` column with HTML
- Standard field names

### Chipy Format
- `casino_name` column (maps to `title`)
- `bonus_text` column (maps to `welcome_bonus`)
- `language` column (single value, maps to `languages` array)
- `local_image_path` column (auto-uploads images)

## Example CSV Row (Chipy Format)

```csv
casino_name,bonus_text,language,rating,local_image_path,casino_url
Winota Casino,"100% + 200 FS",no,3.7,images/winota_casino.png,https://www.winota.com
```

Results in:
- `title`: "Winota Casino"
- `slug`: "winota-casino-review"
- `languages`: ["no"]
- `rating`: 7.4 (3.7 × 2)
- `welcome_bonus`: {"bonus_text": {"no": "100% + 200 FS"}}
- `thumbnail`: "post-thumbnails/winota_casino_1234567890.png" (auto-uploaded)
- `casino_url`: "https://www.winota.com"
- `min_deposit`: {"no": "200"} (random if missing)
- `max_withdrawal`: {"no": "50,000"} (random if missing)
- `casino_rtp`: 96.5 (random if missing)
