-- ============================================
-- Inventory Management App - Database Setup
-- ============================================

-- Create dealer_users table
CREATE TABLE IF NOT EXISTS dealer_users (
    user_id INT(11) PRIMARY KEY AUTO_INCREMENT,
    DBID VARCHAR(75) NOT NULL,
    username VARCHAR(50) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL,
    email VARCHAR(100),
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    role ENUM('dealer', 'admin') DEFAULT 'dealer',
    active TINYINT(1) DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    last_login TIMESTAMP NULL,
    INDEX(DBID),
    INDEX(username),
    INDEX(role)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Create default admin account
-- Username: admin
-- Password: Admin123! (CHANGE THIS IMMEDIATELY AFTER FIRST LOGIN)
INSERT INTO dealer_users (DBID, username, password, email, first_name, last_name, role, active) 
VALUES (
    'ADMIN',
    'admin',
    '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 
    'admin@websites4dealers.com',
    'System',
    'Administrator',
    'admin',
    1
);

-- Sample dealer account
-- Username: dealer1
-- Password: Dealer123! (CHANGE THIS)
INSERT INTO dealer_users (DBID, username, password, email, first_name, last_name, role, active) 
VALUES (
    'dealer_001',
    'dealer1',
    '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
    'dealer1@example.com',
    'Demo',
    'Dealer',
    'dealer',
    1
);

-- ============================================
-- IMPORTANT: After running this SQL:
-- 1. Change the admin password immediately
-- 2. Update DBID values to match your dealer IDs
-- 3. Delete or update the sample dealer account
-- ============================================
