-- Migration: Add login credentials to clients table
-- Run this SQL to allow clients to login

-- Add username and password columns to clients table
ALTER TABLE clients
ADD COLUMN username VARCHAR(50) UNIQUE NULL AFTER broker_id,
ADD COLUMN password VARCHAR(255) NULL AFTER username,
ADD COLUMN last_login TIMESTAMP NULL AFTER access_status;

-- Create index for faster username lookups
CREATE INDEX idx_clients_username ON clients(username);

-- Update existing clients to have username based on phone number (optional)
-- You can run this if you want existing clients to have automatic usernames
-- UPDATE clients SET username = CONCAT('client_', phone) WHERE username IS NULL;
