# 데이터 모델

## 개념

| 엔티티 | 역할 |
|--------|------|
| **courses** | 과정 카탈로그 (프론트 `src/data/courses.js` 고정). Meet은 여기 없음. |
| **class_sessions** | 관리자가 연 **실제 강의**. 날짜·시간·Meet·교안·open/closed |
| **bookings** | 학생의 세션 신청 (pending → approved / rejected) |
| **enrollments** | 승인 후 수강 이력 (active / ended) |
| **users** | 학생·관리자 프로필 |

학생은 **열린 세션**에만 신청할 수 있고, 승인 후 해당 세션의 Meet·materials를 봅니다.

## Supabase SQL (권장)

```sql
-- profiles (auth.users 와 1:1)
create table public.users (
  id uuid primary key references auth.users on delete cascade,
  email text not null,
  name text,
  phone text,
  role text not null default 'student' check (role in ('student','admin')),
  created_at timestamptz default now()
);

create table public.class_sessions (
  id uuid primary key default gen_random_uuid(),
  course_id text not null,
  title text not null,
  session_date date not null,
  start_time text not null,
  end_time text,
  meet_link text,
  materials_url text,
  capacity int,
  status text not null default 'open' check (status in ('open','closed','cancelled')),
  created_by uuid references public.users(id),
  created_at timestamptz default now()
);

create table public.bookings (
  id uuid primary key default gen_random_uuid(),
  student_id uuid references public.users(id),
  student_name text,
  student_email text,
  student_phone text,
  session_id uuid references public.class_sessions(id),
  course_id text,
  class_title text,
  class_date text,
  class_time text,
  memo text,
  status text not null default 'pending' check (status in ('pending','approved','rejected')),
  meet_link text,
  created_at timestamptz default now(),
  approved_at timestamptz
);

create table public.enrollments (
  id uuid primary key default gen_random_uuid(),
  student_id uuid not null references public.users(id),
  course_id text not null,
  session_id uuid references public.class_sessions(id),
  status text not null default 'active' check (status in ('active','ended')),
  enrolled_at timestamptz default now(),
  ended_at timestamptz,
  student_name text,
  student_email text
);

alter table public.users enable row level security;
alter table public.class_sessions enable row level security;
alter table public.bookings enable row level security;
alter table public.enrollments enable row level security;

-- 예시 정책 (운영에 맞게 강화하세요)
create policy "sessions public read open"
  on public.class_sessions for select using (true);

create policy "bookings own"
  on public.bookings for all using (auth.uid() = student_id);

-- 관리자 역할은 users.role = 'admin' 기준으로 정책 추가 권장
```

## localStorage 키 (local 모드)

- `edu_pro_users_v3`
- `edu_pro_session_v3`
- `edu_pro_sessions_v3`
- `edu_pro_bookings_v3`
- `edu_pro_enrollments_v3`
- `edu_pro_seeded_v3` (알고리즘 샘플 세션 1회 시드)
