# API Request Examples - Profile Update Request

## 🎯 Complete Workflow with Real Examples

### Step 1: Upload Logo Image

**Request:**
```http
POST /api/media HTTP/1.1
Host: your-domain.com
Authorization: Bearer {vendor_token}
Content-Type: multipart/form-data

------WebKitFormBoundary
Content-Disposition: form-data; name="file"; filename="store-logo.jpg"
Content-Type: image/jpeg

[binary data]
------WebKitFormBoundary
Content-Disposition: form-data; name="model"

Profile
------WebKitFormBoundary
Content-Disposition: form-data; name="media_type"

image
------WebKitFormBoundary
Content-Disposition: form-data; name="width"

800
------WebKitFormBoundary
Content-Disposition: form-data; name="height"

800
------WebKitFormBoundary
Content-Disposition: form-data; name="quality"

85
------WebKitFormBoundary--
```

**Response:**
```json
{
  "status": true,
  "message": "File uploaded successfully",
  "data": {
    "id": "9d4f8a2b-1c3e-4d5f-8a9b-1c2d3e4f5a6b",
    "type": "image"
  }
}
```

**💾 Save this ID:** `9d4f8a2b-1c3e-4d5f-8a9b-1c2d3e4f5a6b`

---

### Step 2: Upload Commercial Register File

**Request:**
```http
POST /api/media HTTP/1.1
Host: your-domain.com
Authorization: Bearer {vendor_token}
Content-Type: multipart/form-data

------WebKitFormBoundary
Content-Disposition: form-data; name="file"; filename="commercial-register.pdf"
Content-Type: application/pdf

[binary data]
------WebKitFormBoundary
Content-Disposition: form-data; name="model"

Profile
------WebKitFormBoundary
Content-Disposition: form-data; name="media_type"

pdf
------WebKitFormBoundary
Content-Disposition: form-data; name="generate_thumbnail"

true
------WebKitFormBoundary--
```

**Response:**
```json
{
  "status": true,
  "message": "File uploaded successfully",
  "data": {
    "id": "9d4f8a2b-5678-4d5f-8a9b-abcdef123456",
    "type": "pdf",
    "thumbnail_name": "https://domain.com/storage/files/thumbnail.jpg"
  }
}
```

**💾 Save this ID:** `9d4f8a2b-5678-4d5f-8a9b-abcdef123456`

---

### Step 3: Create Profile Update Request

**Request:**
```http
POST /api/dashboard/vendor/profile-update-requests HTTP/1.1
Host: your-domain.com
Authorization: Bearer {vendor_token}
Content-Type: application/json

{
  "logo": "9d4f8a2b-1c3e-4d5f-8a9b-1c2d3e4f5a6b",
  "commercial_register_file": "9d4f8a2b-5678-4d5f-8a9b-abcdef123456",
  "commercial_register_number": "CR-2024-123456",
  "ar": {
    "name": "متجر الإلكترونيات الحديثة",
    "description": "نحن متجر متخصص في بيع الأجهزة الإلكترونية والهواتف الذكية بأفضل الأسعار وأعلى جودة في المملكة العربية السعودية"
  },
  "en": {
    "name": "Modern Electronics Store",
    "description": "We are a store specialized in selling electronic devices and smartphones at the best prices and highest quality in the Kingdom of Saudi Arabia"
  },
  "location": {
    "country_id": 1,
    "city_id": 5,
    "lat": 24.7136,
    "lng": 46.6753,
    "name": "Main Branch - Riyadh",
    "property_number": "1234",
    "details": "Building 15, Floor 2, Office 201, Near King Fahd Road",
    "url": "https://maps.google.com/?q=24.7136,46.6753"
  }
}
```

**Response:**
```json
{
  "status": true,
  "message": "Profile update request submitted successfully.",
  "data": {
    "id": 1,
    "profile_data": {
      "logo": "9d4f8a2b-1c3e-4d5f-8a9b-1c2d3e4f5a6b",
      "commercial_register_file": "9d4f8a2b-5678-4d5f-8a9b-abcdef123456",
      "commercial_register_number": "CR-2024-123456",
      "translations": {
        "ar": {
          "name": "متجر الإلكترونيات الحديثة",
          "description": "نحن متجر متخصص في بيع الأجهزة الإلكترونية..."
        },
        "en": {
          "name": "Modern Electronics Store",
          "description": "We are a store specialized in selling electronic devices..."
        }
      }
    },
    "location_data": {
      "country_id": 1,
      "city_id": 5,
      "lat": 24.7136,
      "lng": 46.6753,
      "name": "Main Branch - Riyadh",
      "property_number": "1234",
      "details": "Building 15, Floor 2, Office 201, Near King Fahd Road",
      "url": "https://maps.google.com/?q=24.7136,46.6753"
    },
    "status": "pending",
    "admin_note": null,
    "created_at": "2026-04-20 12:30:45",
    "updated_at": "2026-04-20 12:30:45"
  }
}
```

---

## 📋 More Examples

### Example 1: Minimal Request (Only Required Fields)

```json
{
  "ar": {
    "name": "متجر الإلكترونيات",
    "description": "متجر متخصص في بيع الأجهزة الإلكترونية والهواتف الذكية"
  },
  "en": {
    "name": "Electronics Store",
    "description": "Store specialized in selling electronic devices and smartphones"
  }
}
```

### Example 2: Update Logo Only

```json
{
  "logo": "9d4f8a2b-1c3e-4d5f-8a9b-1c2d3e4f5a6b",
  "ar": {
    "name": "متجر الإلكترونيات",
    "description": "متجر متخصص في بيع الأجهزة الإلكترونية"
  },
  "en": {
    "name": "Electronics Store",
    "description": "Store specialized in selling electronic devices"
  }
}
```

### Example 3: Update Commercial Register Only

```json
{
  "commercial_register_file": "9d4f8a2b-5678-4d5f-8a9b-abcdef123456",
  "commercial_register_number": "CR-2024-789012",
  "ar": {
    "name": "متجر الإلكترونيات",
    "description": "متجر متخصص في بيع الأجهزة الإلكترونية"
  },
  "en": {
    "name": "Electronics Store",
    "description": "Store specialized in selling electronic devices"
  }
}
```

### Example 4: Update Location Only

```json
{
  "ar": {
    "name": "متجر الإلكترونيات",
    "description": "متجر متخصص في بيع الأجهزة الإلكترونية"
  },
  "en": {
    "name": "Electronics Store",
    "description": "Store specialized in selling electronic devices"
  },
  "location": {
    "country_id": 1,
    "city_id": 10,
    "lat": 21.4225,
    "lng": 39.8262,
    "name": "Jeddah Branch",
    "property_number": "5678",
    "details": "Al Andalus District, Building 20",
    "url": "https://maps.google.com/?q=21.4225,39.8262"
  }
}
```

### Example 5: Update Everything

```json
{
  "logo": "9d4f8a2b-1c3e-4d5f-8a9b-1c2d3e4f5a6b",
  "commercial_register_file": "9d4f8a2b-5678-4d5f-8a9b-abcdef123456",
  "commercial_register_number": "CR-2024-123456",
  "ar": {
    "name": "متجر الإلكترونيات الحديثة - الفرع الرئيسي",
    "description": "نحن متجر رائد في مجال الإلكترونيات، نقدم أحدث الأجهزة والهواتف الذكية بأفضل الأسعار وأعلى جودة. نفخر بخدمة عملائنا في جميع أنحاء المملكة"
  },
  "en": {
    "name": "Modern Electronics Store - Main Branch",
    "description": "We are a leading electronics store, offering the latest devices and smartphones at the best prices and highest quality. We pride ourselves on serving our customers throughout the Kingdom"
  },
  "location": {
    "country_id": 1,
    "city_id": 5,
    "lat": 24.7136,
    "lng": 46.6753,
    "name": "Main Branch - Riyadh",
    "property_number": "1234",
    "details": "Building 15, Floor 2, Office 201, Near King Fahd Road, Olaya District",
    "url": "https://maps.google.com/?q=24.7136,46.6753"
  }
}
```

---

## 🔍 Admin Actions

### Get All Pending Requests

**Request:**
```http
GET /api/dashboard/admin/profile-update-requests?status=pending&per_page=20 HTTP/1.1
Host: your-domain.com
Authorization: Bearer {admin_token}
```

**Response:**
```json
{
  "status": true,
  "data": [
    {
      "id": 1,
      "vendor": {
        "id": 25,
        "name": "Ahmed Electronics",
        "email": "ahmed@electronics.com",
        "logo": {
          "id": "old-logo-id",
          "path": "https://domain.com/storage/images/old-logo.jpg",
          "type": "image",
          "option": "logo"
        }
      },
      "status": "pending",
      "created_at": "2026-04-20 12:30:45",
      "updated_at": "2026-04-20 12:30:45"
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 20,
    "total": 1
  }
}
```

### Get Request Details

**Request:**
```http
GET /api/dashboard/admin/profile-update-requests/1 HTTP/1.1
Host: your-domain.com
Authorization: Bearer {admin_token}
```

**Response:**
```json
{
  "status": true,
  "data": {
    "id": 1,
    "vendor": {
      "id": 25,
      "name": "Ahmed Electronics",
      "email": "ahmed@electronics.com",
      "logo": {
        "id": "old-logo-id",
        "path": "https://domain.com/storage/images/old-logo.jpg"
      }
    },
    "profile_data": {
      "logo": "9d4f8a2b-1c3e-4d5f-8a9b-1c2d3e4f5a6b",
      "commercial_register_file": "9d4f8a2b-5678-4d5f-8a9b-abcdef123456",
      "commercial_register_number": "CR-2024-123456",
      "translations": {
        "ar": {
          "name": "متجر الإلكترونيات الحديثة",
          "description": "نحن متجر متخصص..."
        },
        "en": {
          "name": "Modern Electronics Store",
          "description": "We are a store specialized..."
        }
      }
    },
    "location_data": {
      "country_id": 1,
      "city_id": 5,
      "lat": 24.7136,
      "lng": 46.6753,
      "name": "Main Branch - Riyadh",
      "property_number": "1234",
      "details": "Building 15, Floor 2",
      "url": "https://maps.google.com/?q=24.7136,46.6753"
    },
    "current_profile": {
      "logo": {
        "id": "old-logo-id",
        "path": "https://domain.com/storage/images/old-logo.jpg"
      },
      "commercial_register_number": "CR-2023-999999",
      "commercial_register_file": {
        "id": "old-file-id",
        "path": "https://domain.com/storage/files/old-register.pdf"
      },
      "translations": [
        {
          "locale": "ar",
          "name": "متجر الإلكترونيات القديم",
          "description": "وصف قديم"
        },
        {
          "locale": "en",
          "name": "Old Electronics Store",
          "description": "Old description"
        }
      ]
    },
    "current_location": {
      "id": 10,
      "country_id": 1,
      "city_id": 3,
      "lat": 24.5,
      "lng": 46.5,
      "name": "Old Location"
    },
    "status": "pending",
    "admin_note": null,
    "created_at": "2026-04-20 12:30:45",
    "updated_at": "2026-04-20 12:30:45"
  }
}
```

### Approve Request

**Request:**
```http
POST /api/dashboard/admin/profile-update-requests/1/approve HTTP/1.1
Host: your-domain.com
Authorization: Bearer {admin_token}
Content-Type: application/json

{}
```

**Response:**
```json
{
  "status": true,
  "message": "Profile update request approved successfully.",
  "data": {
    "id": 1,
    "status": "approved",
    "admin_note": null,
    "created_at": "2026-04-20 12:30:45",
    "updated_at": "2026-04-20 13:15:22"
  }
}
```

### Reject Request

**Request:**
```http
POST /api/dashboard/admin/profile-update-requests/1/reject HTTP/1.1
Host: your-domain.com
Authorization: Bearer {admin_token}
Content-Type: application/json

{
  "reason": "الصورة المرفقة للسجل التجاري غير واضحة. يرجى رفع مستند بجودة أعلى وتأكد من أن جميع التفاصيل مقروءة."
}
```

**Response:**
```json
{
  "status": true,
  "message": "Profile update request rejected successfully.",
  "data": {
    "id": 1,
    "status": "rejected",
    "admin_note": "الصورة المرفقة للسجل التجاري غير واضحة. يرجى رفع مستند بجودة أعلى وتأكد من أن جميع التفاصيل مقروءة.",
    "created_at": "2026-04-20 12:30:45",
    "updated_at": "2026-04-20 13:20:10"
  }
}
```

---

## ❌ Error Responses

### Error: Pending Request Already Exists

**Request:**
```json
{
  "logo": "new-logo-id",
  "ar": {"name": "...", "description": "..."},
  "en": {"name": "...", "description": "..."}
}
```

**Response:**
```json
{
  "status": false,
  "message": "You already have a pending profile update request."
}
```

### Error: Invalid Media ID

**Request:**
```json
{
  "logo": "invalid-media-id",
  "ar": {"name": "...", "description": "..."},
  "en": {"name": "...", "description": "..."}
}
```

**Response:**
```json
{
  "status": false,
  "message": "The given data was invalid.",
  "errors": {
    "logo": [
      "The selected logo is invalid."
    ]
  }
}
```

### Error: Missing Required Fields

**Request:**
```json
{
  "logo": "valid-media-id"
}
```

**Response:**
```json
{
  "status": false,
  "message": "The given data was invalid.",
  "errors": {
    "ar.name": [
      "The ar.name field is required."
    ],
    "ar.description": [
      "The ar.description field is required."
    ],
    "en.name": [
      "The en.name field is required."
    ],
    "en.description": [
      "The en.description field is required."
    ]
  }
}
```

---

## 🎯 Field Specifications

| Field | Type | Required | Validation | Example |
|-------|------|----------|------------|---------|
| `logo` | string (UUID) | No | exists:media,id | `9d4f8a2b-1c3e-4d5f-8a9b-1c2d3e4f5a6b` |
| `commercial_register_file` | string (UUID) | No | exists:media,id | `9d4f8a2b-5678-4d5f-8a9b-abcdef123456` |
| `commercial_register_number` | string | No | - | `CR-2024-123456` |
| `ar.name` | string | Yes | 2-100 chars | `متجر الإلكترونيات` |
| `ar.description` | string | Yes | 2-1000 chars | `وصف المتجر...` |
| `en.name` | string | Yes | 2-100 chars | `Electronics Store` |
| `en.description` | string | Yes | 2-1000 chars | `Store description...` |
| `location.country_id` | integer | No | exists:countries,id | `1` |
| `location.city_id` | integer | No | exists:cities,id | `5` |
| `location.lat` | numeric | No | - | `24.7136` |
| `location.lng` | numeric | No | - | `46.6753` |
| `location.name` | string | No | - | `Main Branch` |
| `location.property_number` | string | No | - | `1234` |
| `location.details` | string | No | - | `Building 15...` |
| `location.url` | string | No | - | `https://maps.google.com/...` |
