# Quick Setup Guide

## Before You Start

1. **Start MAMP**
   - Open MAMP application
   - Click "Start Servers" to start Apache and MySQL
   - Note the MySQL port (usually 8889)
   - Ensure both Apache and MySQL indicators are green

2. **Create Database**
   - Open phpMyAdmin (http://localhost/phpMyAdmin/)
   - Create a new database named `saca`
   - Or use MySQL command line:
     ```bash
     /Applications/MAMP/Library/bin/mysql -u root -P 8889 -h 127.0.0.1 -e "CREATE DATABASE saca;"
     ```

3. **Run Migrations**
   ```bash
   cd /Applications/MAMP/htdocs/saca/backend
   php artisan migrate
   ```

4. **Start Laravel Server**
   ```bash
   php artisan serve
   ```

## Test the API

Once everything is running, test these endpoints:

- **Test endpoint:** http://127.0.0.1:8000/api/test
- **Register:** POST http://127.0.0.1:8000/api/register
- **Login:** POST http://127.0.0.1:8000/api/login

## Example API Test with curl

```bash
# Test endpoint
curl http://127.0.0.1:8000/api/test

# Register users with different types
# Admin user
curl -X POST http://127.0.0.1:8000/api/register \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "name": "Admin User",
    "email": "admin@example.com",
    "password": "password123",
    "password_confirmation": "password123",
    "user_type": "admin"
  }'

# Trial user
curl -X POST http://127.0.0.1:8000/api/register \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "name": "Trial User",
    "email": "trial@example.com",
    "password": "password123",
    "password_confirmation": "password123",
    "user_type": "trial"
  }'

# Survey user
curl -X POST http://127.0.0.1:8000/api/register \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "name": "Survey User",
    "email": "survey@example.com",
    "password": "password123",
    "password_confirmation": "password123",
    "user_type": "survey"
  }'

# Role-based login endpoints
# Admin login
curl -X POST http://127.0.0.1:8000/api/login/admin \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "email": "admin@example.com",
    "password": "password123"
  }'

# Trial login
curl -X POST http://127.0.0.1:8000/api/login/trial \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "email": "trial@example.com",
    "password": "password123"
  }'

# Survey login
curl -X POST http://127.0.0.1:8000/api/login/survey \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "email": "survey@example.com",
    "password": "password123"
  }'
```

## Frontend Integration

Your Next.js frontend can now connect to this API at `http://127.0.0.1:8000/api/`

The API includes:
- ✅ Role-based authentication (admin, trial, survey)
- ✅ User type validation and middleware protection
- ✅ Dashboard URLs for different user types
- ✅ CORS configuration for localhost:3000
- ✅ Laravel Sanctum for secure API tokens
- ✅ Input validation and error handling

### User Types and Dashboard URLs

- **Admin users**: Dashboard at `/en/data/login`
- **Trial users**: Dashboard at `/en/data/trial`
- **Survey users**: Dashboard at `/en/data/survey`

### Protected Dashboard Endpoints

After successful login, users can access their respective dashboards:

```bash
# Access admin dashboard (requires admin token)
curl -X GET http://127.0.0.1:8000/api/dashboard/admin \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -H "Accept: application/json"

# Access trial dashboard (requires trial token)
curl -X GET http://127.0.0.1:8000/api/dashboard/trial \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -H "Accept: application/json"

# Access survey dashboard (requires survey token)
curl -X GET http://127.0.0.1:8000/api/dashboard/survey \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -H "Accept: application/json"
```

## Next Steps

1. Start MAMP and ensure MySQL is running
2. Create the `saca` database
3. Run migrations to create tables with user_type field
4. Test the API endpoints with different user types
5. Integrate with your Next.js frontend using the provided dashboard URLs
6. Implement role-based redirects in your frontend based on user_type