# Local Setup Guide

## Before You Start

Make sure you have:
- Node.js 18+ installed
- PostgreSQL database credentials:
  - Host: `127.0.0.200`
  - Port: `5432`
  - Database: `inatetec_southwest_auto`
  - User: `inatetec_sw_auto_user`
  - Password: `hypke4-totpir-vyCgab`

## Quick Start

1. **Clone or copy the code** to your local machine

2. **Install dependencies:**
   ```bash
   npm install
   ```

3. **Run database migrations** (creates tables):
   ```bash
   npm run db:migrate
   ```

4. **Update `.env.local`** with your SMTP credentials:
   - `SMTP_USER` - your email address
   - `SMTP_PASSWORD` - your email app password (Gmail, SendGrid, etc.)
   - `SHOP_MANAGER_EMAIL` - where appointment notifications should go

5. **Start the development server:**
   ```bash
   npm run dev
   ```

6. **Open your browser:**
   Visit http://localhost:3000

## Testing the Features

### Test Appointment Booking
1. Go to http://localhost:3000/appointments
2. Fill out the form with test data
3. Submit
4. Check your SHOP_MANAGER_EMAIL inbox for the notification
5. Visit http://localhost:3000/admin/dashboard
6. Approve the appointment
7. Check your test email inbox for confirmation

### Test Review Management
1. Add test reviews directly to the database:
   ```sql
   INSERT INTO reviews (author, rating, text, source, approved, created_at)
   VALUES ('John Smith', 5, 'Great service!', 'Google', false, NOW());
   ```

2. Go to http://localhost:3000/admin/dashboard
3. Approve the review
4. Visit http://localhost:3000/reviews to see it displayed

## Database Management

### Connect to Bluehost PostgreSQL locally

If you want to test against the live database:

```bash
psql -h 127.0.0.200 -U inatetec_sw_auto_user -d inatetec_southwest_auto
```

Then query:
```sql
SELECT * FROM appointments;
SELECT * FROM reviews;
```

### Reset Database (Warning: Destructive)

```bash
psql -h 127.0.0.200 -U inatetec_sw_auto_user -d inatetec_southwest_auto
DROP TABLE appointments;
DROP TABLE reviews;
```

Then run migrations again:
```bash
npm run db:migrate
```

## Common Issues

**Error: "Cannot find module 'pg'"**
- Run `npm install` to ensure all dependencies are installed

**Error: "connect ECONNREFUSED 127.0.0.200:5432"**
- Make sure database credentials in `.env.local` are correct
- Verify Bluehost PostgreSQL is accessible from your network

**Emails not sending**
- Check SMTP credentials
- Gmail requires an "App Password" (not your regular password)
- Look for error messages in terminal output

## Next Steps

Once everything works locally:
1. Push code to GitHub (if using version control)
2. Follow BLUEHOST-DEPLOYMENT.md to deploy
3. Set up Google Reviews integration (Task #3)

## Need Help?

Check the README.md or BLUEHOST-DEPLOYMENT.md for more info.
