-- Store Keeper Mobile API alignment v24
-- Safe additive migration: no existing columns are renamed or removed.

ALTER TABLE users
  ADD COLUMN IF NOT EXISTS user_code VARCHAR(80) NULL AFTER phone,
  ADD COLUMN IF NOT EXISTS default_warehouse_id BIGINT UNSIGNED NULL AFTER user_code,
  ADD COLUMN IF NOT EXISTS mobile_device_id VARCHAR(255) NULL AFTER default_warehouse_id;

CREATE INDEX IF NOT EXISTS idx_users_tenant_user_code_mobile ON users (tenant_id, user_code, user_type, is_delete);
CREATE INDEX IF NOT EXISTS idx_users_default_warehouse_mobile ON users (tenant_id, default_warehouse_id, is_delete);

CREATE INDEX IF NOT EXISTS idx_mobile_pick_tasks_wh_status ON pick_tasks (tenant_id, warehouse_id, status, is_delete);
CREATE INDEX IF NOT EXISTS idx_mobile_pick_items_task_sku ON pick_task_items (tenant_id, pick_task_id, sku_code, status, is_delete);
CREATE INDEX IF NOT EXISTS idx_mobile_pack_tasks_wh_status ON pack_tasks (tenant_id, warehouse_id, status, is_delete);
CREATE INDEX IF NOT EXISTS idx_mobile_locations_search ON warehouse_locations (tenant_id, warehouse_id, status, is_delete);
CREATE INDEX IF NOT EXISTS idx_mobile_parcel_search ON parcel_holdings (tenant_id, warehouse_id, parcel_no, awb_no, is_delete);
CREATE INDEX IF NOT EXISTS idx_mobile_inventory_search ON inventory_stocks (tenant_id, warehouse_id, sku_code, barcode, is_delete);
CREATE INDEX IF NOT EXISTS idx_mobile_shipping_label_scan ON shipping_labels (tenant_id, label_no, tracking_no, is_delete);
