########################################
# 6) SERVICE CATEGORIES & SERVICES (فئات الخدمات والخدمات)
########################################

We want to define the core services module for the salon, linked to the inventory products.
This will be used later when creating sales/service orders to:
- Select services
- Automatically consume related products from stock

### Table: service_categories
Categories of services (e.g., شعر، أظافر، مكياج...).

Fields:
- id (integer, primary key, auto increment)
- name_ar (string, not null)          // اسم الفئة (مثال: "خدمات الشعر")
- code (string, nullable, unique)     // رمز الفئة (اختياري)
- image_url (string, nullable)        // صورة توضيحية للفئة
- is_active (boolean, default true)   // لتفعيل/إلغاء تفعيل الفئة
- created_at (datetime)
- updated_at (datetime)

Requirements:
- API to list all categories, including:
  - id, name_ar, code, image_url, is_active
  - services_count: number of active services in this category
- Ability to activate/deactivate a category (update is_active).

### Table: services
Defines the services provided by the salon (e.g., قص شعر، صبغة، منيكير...).

Fields:
- id (integer, primary key, auto increment)
- category_id (integer, foreign key to service_categories.id)   // الفئة التي تنتمي إليها الخدمة
- name_ar (string, not null)            // اسم الخدمة
- code (string, nullable, unique)       // رمز الخدمة (اختياري، مثل SH-001)
- description_ar (string, nullable)     // وصف الخدمة
- price (real, not null)                // سعر الخدمة
- vat_type (string, not null)           // "inclusive" (شامل), "exclusive" (غير شامل), "exempt" (معفي)
- vat_rate (real, not null)             // مثال: 0.15
- is_active (boolean, default true)     // لتفعيل/إلغاء تفعيل الخدمة
- created_at (datetime)
- updated_at (datetime)

Notes:
- Later, when we build the sales/service orders module, we will:
  - Use price + vat_type + vat_rate to calculate line_subtotal, vat_amount, line_total
  - Link the service to related products (below) to auto consume stock.

### Table: service_products
Related products for each service, coming from the products (inventory) module.

When a service is performed in a sales/service order, the system will know which products to consume from stock.

Fields:
- id (integer, primary key, auto increment)
- service_id (integer, foreign key to services.id)
- product_id (integer, foreign key to products.id)
- quantity_per_service (real, not null, default 1)   // الكمية المستهلكة من المنتج لكل عملية خدمة واحدة (بوحدة البيع للمنتج)
- notes (string, nullable)                           // ملاحظات اختيارية

Requirements:
- It should be possible to attach multiple products to a single service.
- Later, when we build the sales module, these related products will be automatically pulled and used to create stock_movements of type "consume".

### Service Categories APIs

1) GET /service-categories
   - List all service categories.
   - Response should include:
     - id, name_ar, code, image_url, is_active
     - services_count (number of active services in this category).

2) POST /service-categories
   - Create a new service category.
   - Request JSON example:
   {
     "name_ar": "خدمات الشعر",
     "code": "HAIR",
     "image_url": "https://example.com/hair.jpg",
     "is_active": true
   }

3) GET /service-categories/:id
   - Get a single category by id, including:
     - basic category fields
     - list of its services (id, name_ar, code, price, is_active).

4) PUT /service-categories/:id
   - Update a category (name, code, image_url, is_active).

5) DELETE /service-categories/:id
   - Soft delete OR simply set is_active = false (you can choose the simplest approach consistent with the rest of the app).

### Services APIs

1) GET /services
   - List all services with optional filters:
     - ?category_id=
     - ?is_active=true/false
   - Return:
     - id, name_ar, code, price, vat_type, vat_rate, is_active, category_id, category_name_ar

2) POST /services
   - Create a new service with optional related products.
   - Request JSON example:
   {
     "category_id": 1,
     "name_ar": "قص شعر سيدات",
     "code": "HR-CUT-01",
     "description_ar": "قص شعر مع تسريح بسيط",
     "price": 120,
     "vat_type": "inclusive",          // "inclusive", "exclusive", "exempt"
     "vat_rate": 0.15,
     "is_active": true,
     "related_products": [
       {
         "product_id": 10,
         "quantity_per_service": 0.5   // نصف عبوة سبراي مثلاً
       },
       {
         "product_id": 12,
         "quantity_per_service": 1
       }
     ]
   }

   Behavior:
   - Validate category_id exists and is_active.
   - Validate all product_id in related_products exist in products table.
   - Create the service record.
   - Insert related rows into service_products.

3) GET /services/:id
   - Return full service details:
     - id, category_id, name_ar, code, description_ar, price, vat_type, vat_rate, is_active
     - category_name_ar
     - related_products: list of { product_id, product_name_ar, quantity_per_service }

4) PUT /services/:id
   - Update service fields.
   - Optionally replace related_products:
     - Simplest approach: delete old service_products for this service and insert the new list.

   Request JSON example (similar to POST):
   {
     "category_id": 2,
     "name_ar": "صبغة شعر كاملة",
     "code": "HR-COLOR-01",
     "description_ar": "صبغة كاملة مع غسل وتجفيف",
     "price": 250,
     "vat_type": "exclusive",
     "vat_rate": 0.15,
     "is_active": true,
     "related_products": [
       { "product_id": 15, "quantity_per_service": 1 },
       { "product_id": 20, "quantity_per_service": 0.25 }
     ]
   }

5) DELETE /services/:id
   - Soft delete (set is_active = false), do not physically delete rows.

### Validation & Arabic messages

- When category_id does not exist:
  - Return error in Arabic, e.g.: "فئة الخدمة غير موجودة".
- When product_id in related_products does not exist:
  - Return error: "المنتج المرتبط غير موجود".
- When creating a service without name_ar or price:
  - Return error: "اسم الخدمة مطلوب" ، "سعر الخدمة مطلوب".

