-- Legacy Postgres/Supabase reference. Production uses MySQL: see schema.mysql.sql
-- Products may remain static or move to a `products` table; orders + entitlements are required for commerce.

create table if not exists public.profiles (
  id uuid primary key references auth.users on delete cascade,
  email text unique not null,
  full_name text,
  role text default 'user' check (role in ('user', 'admin')),
  created_at timestamptz default now()
);

create table if not exists public.orders (
  id uuid primary key default gen_random_uuid(),
  user_email text not null,
  total_inr integer not null,
  discount_inr integer default 0,
  coupon_code text,
  status text not null,
  razorpay_order_id text,
  razorpay_payment_id text,
  razorpay_subscription_id text,
  created_at timestamptz default now()
);

create table if not exists public.order_items (
  id uuid primary key default gen_random_uuid(),
  order_id uuid references public.orders(id) on delete cascade,
  product_id text not null,
  title text not null,
  amount_inr integer not null,
  quantity integer not null default 1
);

create table if not exists public.entitlements (
  user_email text not null,
  product_id text not null,
  created_at timestamptz default now(),
  primary key (user_email, product_id)
);
