create table if not exists consulting_requests (
  id uuid primary key default gen_random_uuid(),
  request_no text not null unique,
  user_id uuid not null references users(id) on delete cascade,
  status text not null default 'pending',
  current_step integer not null default 0,
  company text not null default '',
  contact_name text not null default '',
  contact_phone text not null default '',
  email text not null default '',
  direction text not null default '',
  organization_type text not null default '',
  industry text not null default '',
  city text not null default '',
  project_stage text not null default '',
  urgency text not null default '',
  budget_range text not null default '',
  expected_start text not null default '',
  current_situation text not null default '',
  requirement text not null default '',
  goals text not null default '',
  preferred_contact_time text not null default '',
  owner_department text not null default '',
  assigned_account_id uuid references staff_accounts(id) on delete set null,
  progress_note text not null default '',
  solution_summary text not null default '',
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now(),
  accepted_at timestamptz,
  completed_at timestamptz
);

create index if not exists idx_consulting_requests_user_created on consulting_requests(user_id, created_at desc);
create index if not exists idx_consulting_requests_status on consulting_requests(status, updated_at desc);
create index if not exists idx_consulting_requests_assignee on consulting_requests(assigned_account_id, status, updated_at desc);
