# hu-rooms

This is a [Next.js](https://nextjs.org) project bootstrapped with [v0](https://v0.app).

## Built with v0

This repository is linked to a [v0](https://v0.app) project. You can continue developing by visiting the link below -- start new chats to make changes, and v0 will push commits directly to this repo. Every merge to `main` will automatically deploy.

[Continue working on v0 →](https://v0.app/chat/projects/prj_Q1OQLGXBZpElxFwPEzfKpMCdqzrt)

## Getting Started

1) Create local env file:

```bash
cp .env.example .env.local
```

2) Fill your own Supabase keys in `.env.local`.

3) Run the development server:

```bash
pnpm dev
# o: npm run dev
```

### Environment Variables

Required local variables:

- `NEXT_PUBLIC_SUPABASE_URL`
- `NEXT_PUBLIC_SUPABASE_ANON_KEY` (canonical)
- `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY` (optional fallback only in local/dev)
- `SUPABASE_SERVICE_ROLE_KEY` (required for server-side mutations like PoC login preparation and cron no-show updates)
- `ANTHROPIC_API_KEY` (required for Sammy AI agent runtime)
- `SAMMY_CLAUDE_MODELS` (optional, Claude-only fallback chain)
- `BOOKING_LOCAL_TIMEZONE` (optional, IANA tz; default `America/Argentina/Buenos_Aires`) — usada en API de reservas para validar que el rango cae en la ventana del tipo.

In production, keep using `NEXT_PUBLIC_SUPABASE_ANON_KEY` as the only required publishable key.

### Team Collaboration (Queries/Mutations)

To collaborate safely and avoid breaking remote work:

1. Never share real secrets in git, PRs, or chat exports (`.env*` is gitignored).
2. Never edit an already-applied SQL script.
3. Every DB change must be a new incremental script in `scripts/` (`001`, `002`, `003`, ...).
4. Before applying a script, pull latest `main`.
5. After applying a script, update `PLAN.md` with:
   - script name,
   - scope,
   - pending follow-ups.

This keeps all local environments convergent even when multiple people run mutations from different machines.

## Running SQL Updates

Apply scripts in order from `scripts/` in Supabase SQL Editor (or your preferred SQL runner), for example:

1. `scripts/004_reservations_v2_locations_notifications.sql`
2. `scripts/005_resource_type_booking_config.sql`
3. `scripts/006_reminder_advance_minutes.sql`
4. `scripts/009_booking_window_hour_only.sql` — ventana diaria por tipo (`booking_window_start` / `booking_window_end`), solo `slot_size` por hora, migración de tipos en modo día.
5. `scripts/010_time_granularity_60min.sql` — permite `time_granularity = 60min` (grilla y duraciones por hora).
6. `scripts/011_seed_reservations_demo.sql` — inserta reservas de demo de forma idempotente (UUID fijos, `notes = 'Seed demo hu-rooms'`). Ajustá emails, nombres de recurso y fechas en el script antes de ejecutarlo si tu entorno no coincide con el seed `002`.
7. `scripts/012_is_admin_user_email_fallback.sql` — actualiza `public.is_admin_user()` para tratar como admin la sesión cuando el email del JWT coincide con un `public.users` con `role = 'admin'`, aunque `auth.uid()` no coincida con ese `id` (evita joins vacíos a `users` en vistas admin).

If your environment is already partially migrated, run only pending scripts.

### Seed de reservas (alternativa local)

Con `SUPABASE_SERVICE_ROLE_KEY` y `NEXT_PUBLIC_SUPABASE_URL` en `.env.local`:

```bash
pnpm seed:reservations
# o: npm run seed:reservations
```

**Modo automático (consulta la DB y arma horarios):** no usa el JSON fijo; lee `public.users` y `public.resources` (con ventana horaria del tipo vía `resource_types`) y genera hasta 30 reservas en días consecutivos sin solapes por recurso/día.

```bash
pnpm seed:reservations:auto
# si no tenés pnpm: npm run seed:reservations:auto
```

Variables útiles: `SEED_DRY_RUN=1`, `SEED_AUTO_USER_LIMIT`, `SEED_AUTO_RESOURCE_LIMIT`, `SEED_AUTO_DAYS`, `SEED_AUTO_COUNT`, `SEED_AUTO_FIRST_DATE=YYYY-MM-DD`, `SEED_USER_EMAIL_CONTAINS` (ej. `humand.co`), `SEED_LOCAL_ADD_MINUTES_TO_UTC` (default `180` para Chile UTC-3 al convertir hora civil → UTC).

Modo JSON (default de `seed:reservations`): `SEED_RESERVATIONS_JSON=ruta/al/archivo.json` (mismo formato que [`scripts/seed-reservations.default.json`](scripts/seed-reservations.default.json)).

Node 20+ requiere `--env-file` (incluido en el script npm). Si tu Node no lo soporta, exportá las variables a mano y ejecutá `node scripts/seed-reservations.mjs`.

### Seed de usuarios fake + actividad

Este seed crea usuarios demo (`demo.user.XX@humand.co`) y actividad de reservas con estados mezclados (`confirmed`, `checked_in`, `completed`, `cancelled`, `no_show`) para poblar métricas y tablas admin.

```bash
pnpm seed:users-activity
# o: npm run seed:users-activity
```

Opcionales:

- `SEED_FAKE_USERS_COUNT` (default `12`)
- `SEED_FAKE_RESERVATIONS_PER_USER` (default `8`)
- `SEED_FAKE_FUTURE_PER_USER` (default `2`)
- `SEED_DRY_RUN=1` (simula sin insertar)

El script es idempotente por IDs determinísticos y etiqueta las reservas con `notes = 'Seed fake activity hu-rooms'`.

---

Legacy section from template:

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

## Learn More

To learn more, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
- [v0 Documentation](https://v0.app/docs) - learn about v0 and how to use it.

<a href="https://v0.app/chat/api/kiro/clone/sfavaron-hu/hu-rooms" alt="Open in Kiro"><img src="https://pdgvvgmkdvyeydso.public.blob.vercel-storage.com/open%20in%20kiro.svg?sanitize=true" /></a>
