# PROMPT 01 — Database & Migrations

## Context
We are building a Laravel project called **Water Rush**.
We already have the default Laravel `users` table — this is for **admins only**.

---

## Task
Create migrations for the following tables and run them all.

### Tables

1. `customers`
   - id, name, phone, password, is_active (default 1), remember_token, timestamps

2. `customer_addresses`
   - id, customer_id (FK → customers), title, address, lat (decimal 10,7), lng (decimal 10,7), is_default (default 0), timestamps

3. `drivers`
   - id, name, phone, password, vehicle_type, vehicle_number, vehicle_year, is_active (default 1), remember_token, timestamps

4. `categories`
   - id, name, is_active (default 1), timestamps

5. `products`
   - id, category_id (FK → categories), title, description (nullable text), price (decimal 8,2), price_before (nullable decimal 8,2), is_active (default 1), timestamps

6. `product_images`
   - id, product_id (FK → products), image (string), sort_order (default 0), timestamps

7. `sliders`
   - id, image (string), link (nullable string), is_active (default 1), sort_order (default 0), timestamps

8. `promo_codes`
   - id, code (unique string), type (enum: percent, fixed), discount (decimal 8,2), quantity (int), used_count (default 0), expires_at (nullable date), is_active (default 1), timestamps

9. `bundles`
   - id, title, description (nullable text), price (decimal 8,2), price_before (nullable decimal 8,2), is_active (default 1), timestamps

10. `bundle_images`
    - id, bundle_id (FK → bundles), image (string), sort_order (default 0), timestamps

11. `bundle_items`
    - id, bundle_id (FK → bundles), product_id (FK → products), quantity (default 1), timestamps

12. `scheduled_times`
    - id, label (string), time_from (time), time_to (time), is_active (default 1), timestamps

13. `carts`
    - id, customer_id (FK → customers, unique), timestamps

14. `cart_items`
    - id, cart_id (FK → carts), product_id (nullable FK → products), bundle_id (nullable FK → bundles), quantity (default 1), timestamps

15. `orders`
    - id, customer_id (FK → customers), driver_id (nullable FK → drivers), address_id (FK → customer_addresses), promo_code_id (nullable FK → promo_codes), scheduled_time_id (nullable FK → scheduled_times)
    - status (enum: pending, confirmed, preparing, on_the_way, delivered, cancelled — default: pending)
    - payment_method (enum: cod, online)
    - delivery_fee (decimal 8,2 default 0), subtotal (decimal 8,2), total (decimal 8,2)
    - delivery_date (date), notes (nullable text), timestamps

16. `order_items`
    - id, order_id (FK → orders), product_id (nullable FK → products), bundle_id (nullable FK → bundles), quantity (int), unit_price (decimal 8,2), timestamps

---

## Models & Relationships

After migrations, create an Eloquent Model for every table with proper `$fillable` and relationships:

- `Customer` → hasMany `CustomerAddress`, hasOne `Cart`, hasMany `Order`
- `CustomerAddress` → belongsTo `Customer`
- `Cart` → belongsTo `Customer`, hasMany `CartItem`
- `CartItem` → belongsTo `Cart`, belongsTo `Product` (nullable), belongsTo `Bundle` (nullable)
- `Category` → hasMany `Product`
- `Product` → belongsTo `Category`, hasMany `ProductImage`
- `ProductImage` → belongsTo `Product`
- `Bundle` → hasMany `BundleImage`, hasMany `BundleItem`
- `BundleItem` → belongsTo `Bundle`, belongsTo `Product`
- `BundleImage` → belongsTo `Bundle`
- `PromoCode` → hasMany `Order`
- `ScheduledTime` → hasMany `Order`
- `Driver` → hasMany `Order`
- `Order` → belongsTo `Customer`, `Driver` (nullable), `CustomerAddress`, `PromoCode` (nullable), `ScheduledTime` (nullable) — hasMany `OrderItem`
- `OrderItem` → belongsTo `Order`, belongsTo `Product` (nullable), belongsTo `Bundle` (nullable)

---

## Notes
- Use `php artisan make:migration` for each table
- Use `php artisan make:model` for each model
- Run `php artisan migrate` at the end
- Do NOT touch the existing `users` migration
