# API إضافة الأخبار

## الإعداد

أضف مفتاحًا طويلًا وعشوائيًا إلى ملف `.env` ثم امسح كاش الإعدادات:

```env
ARTICLE_API_KEY=ضع_هنا_مفتاحا_عشوائيا_طويلا
```

```bash
php artisan config:clear
```

لا تضع المفتاح داخل الكود أو مستودع Git.

## إنشاء خبر

- المسار: `POST /api/articles`
- الهيدر الإلزامي: `X-API-Key`
- نوع المحتوى: `application/json`
- صورة الغلاف: رابط `http` أو `https` فقط، ولا يقبل المسار رفع ملف.
- `category_id`: رقم تصنيف موجود.
- `status`: إما `draft` أو `published`، والقيمة الافتراضية `draft`.
- المحتوى: أرسل `content_text` أو مصفوفة `content_blocks` على الأقل.
- ترتيب عناصر `content_blocks` في JSON هو ترتيب ظهورها في الخبر.

```bash
curl -X POST "https://example.com/api/articles" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
    "category_id": 2,
    "title": "عنوان الخبر",
    "subtitle": "عنوان فرعي اختياري",
    "description": "ملخص الخبر",
    "author_name": "غرفة الأخبار",
    "main_image_url": "https://cdn.example.com/news/cover.jpg",
    "main_image_caption": "وصف الصورة",
    "content_text": "النص الكامل للخبر",
    "status": "published",
    "published_at": "2026-09-08 12:00:00",
    "is_breaking": false,
    "is_featured": false,
    "tags": ["اقتصاد", "أخبار مصر"],
    "seo_title": "عنوان محركات البحث",
    "meta_description": "وصف محركات البحث",
    "source_url": "https://source.example.com/article"
  }'
```

يمكن استخدام بلوكات منظمة بدل `content_text`:

```json
{
  "content_blocks": [
    {"block_type": "paragraph", "text": "الفقرة الأولى"},
    {"block_type": "heading", "text": "عنوان داخلي"},
    {"block_type": "image", "url": "https://cdn.example.com/inside.jpg", "caption": "وصف الصورة"}
  ]
}
```

الأنواع المدعومة: `paragraph`, `heading`, `image`, `video`, `youtube`, `facebook`, `instagram`, `twitter`, `tiktok`, `quote`, `list`, `table`, `iframe`, `html`.

## الاستجابات

- `201`: تم إنشاء الخبر، وتعود بياناته ورابط عرضه.
- `401`: مفتاح API مفقود أو غير صحيح.
- `422`: إحدى القيم غير صحيحة، وتعود الأخطاء في حقل `errors`.
