# turfslot-utils

Core business logic helpers for booking badminton, table tennis, and tennis turf slots.  
The package provides reusable dataclasses and services to validate slots, detect clashes, and compute prices so that any Python application (web, CLI, or automation) can reuse the same rules.

## Installation

Once released to PyPI:

```bash
pip install turfslot-utils
```

For local development from this repository:

```bash
pip install .
```

## Quick start

```python
from datetime import datetime, timezone

from turfslot_utils import (
    Court,
    SlotPriceCalculator,
    SlotRangeValidator,
    SportAvailabilityChecker,
    CourtNotAvailableError,
)

court = Court(
    court_id="C1",
    sport_type="BADMINTON",
    name="Smash Arena",
    hourly_rate=400,
)

validator = SlotRangeValidator()
slot = validator.validate(
    sport_type="BADMINTON",
    court_id="C1",
    start_time=datetime(2025, 1, 10, 9, 0, tzinfo=timezone.utc),
    end_time=datetime(2025, 1, 10, 11, 0, tzinfo=timezone.utc),
)

checker = SportAvailabilityChecker()
existing_bookings = []  # Populate from your storage layer
try:
    checker.check_availability(slot, existing_bookings)
except CourtNotAvailableError:
    print("Court already booked!")
else:
    total = SlotPriceCalculator().calculate_price(slot, court)
    print(f"Booking confirmed. Price: INR {total}")
```

## Testing

```bash
python -m pytest
```

## Building and publishing

```bash
python -m pip install --upgrade build twine
python -m build
# TestPyPI upload
python -m twine upload --repository testpypi dist/*
# PyPI upload (set TWINE_PASSWORD or use keyring)
python -m twine upload dist/*
```

Keep credentials outside source control and pass them via environment variables or a secure keyring.
