# Quick Start Guide - Local Development

## 🚀 Fastest Way to Get Started

### Option 1: Using Docker (Recommended - 5 minutes)

```bash
# 1. Navigate to payment directory
cd payment

# 2. Start PostgreSQL and Redis with Docker
docker-compose -f docker-compose.local.yml up -d

# 3. Create .env file
cp env.example .env

# 4. Edit .env - set these values:
#    DB_PASSWORD=local_dev_password
#    JWT_SECRET=your_random_secret_key_here_min_32_chars
#    GIN_MODE=debug
#    LOG_FORMAT=text

# 5. Install dependencies and run
go mod download
go run main.go
```

**That's it!** Service will be running at `http://localhost:8080`

### Option 2: Using Setup Scripts

**Windows (PowerShell):**
```powershell
cd payment
.\scripts\setup-local.ps1
```

**Linux/macOS:**
```bash
cd payment
chmod +x scripts/setup-local.sh
./scripts/setup-local.sh
```

### Option 3: Manual Setup

1. **Install PostgreSQL and Redis** (if not using Docker)
2. **Create database:**
   ```sql
   CREATE DATABASE internet;
   CREATE USER payment_user WITH PASSWORD 'local_dev_password';
   GRANT ALL PRIVILEGES ON DATABASE internet TO payment_user;
   ```
3. **Configure .env** (copy from `env.example`)
4. **Run:** `go run main.go`

## ✅ Verify It's Working

```bash
# Health check
curl http://localhost:8080/health

# Expected response:
# {"status":"healthy","timestamp":"..."}
```

## 📝 Quick Test Commands

### Register a Client
```bash
curl -X POST http://localhost:8080/api/v1/clients/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test Company",
    "email": "test@example.com",
    "username": "testuser",
    "password": "testpass123",
    "phone": "254712345678"
  }'
```

### Login
```bash
curl -X POST http://localhost:8080/api/v1/clients/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "testpass123"
  }'
```

### Get Public Packages
```bash
curl http://localhost:8080/api/v1/packages/public?client_id=YOUR_CLIENT_UUID
```

## 🛠️ Common Issues

**Port 8080 already in use?**
- Change `SERVER_PORT=8081` in `.env`

**Database connection failed?**
- Check PostgreSQL is running: `docker-compose -f docker-compose.local.yml ps`
- Verify `.env` has correct `DB_PASSWORD`

**Redis connection failed?**
- Check Redis is running: `redis-cli ping` (should return `PONG`)

## 📚 Next Steps

- Read full [Local Setup Guide](LOCAL_SETUP.md)
- Check [API Documentation](docs/API.md)
- Review [Troubleshooting Guide](TROUBLESHOOTING_DB.md)

## 🎯 Development Tips

**Enable debug mode:**
```env
GIN_MODE=debug
LOG_LEVEL=debug
LOG_FORMAT=text
```

**Hot reload (install air first):**
```bash
go install github.com/cosmtrek/air@latest
air
```

**Run tests:**
```bash
go test ./...
```

