-- DRIVERS
CREATE TABLE drivers (
    id SERIAL PRIMARY KEY,
    full_name VARCHAR(100),
    is_online BOOLEAN DEFAULT FALSE,
    online_since TIMESTAMP,
    status VARCHAR(20) DEFAULT 'free',
    vip_level INT DEFAULT 0,
    advertising_level INT DEFAULT 0,
    is_active BOOLEAN DEFAULT TRUE
);

-- DRIVER LOCATIONS
CREATE TABLE driver_locations (
    driver_id INT PRIMARY KEY,
    latitude DECIMAL(9,6),
    longitude DECIMAL(9,6),
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- ORDERS
CREATE TABLE orders (
    id SERIAL PRIMARY KEY,
    client_lat DECIMAL(9,6),
    client_lng DECIMAL(9,6),
    status VARCHAR(20) DEFAULT 'searching',
    current_driver_id INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- ATTEMPTS
CREATE TABLE order_driver_attempts (
    order_id INT,
    driver_id INT,
    attempted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (order_id, driver_id)
);

-- SCORING SETTINGS
CREATE TABLE scoring_settings (
    id SERIAL PRIMARY KEY,
    key VARCHAR(50) UNIQUE,
    value DECIMAL(10,4)
);

INSERT INTO scoring_settings (key,value) VALUES
('distance_point_per_meter',0.02),
('waiting_point_per_second',0.05),
('vip_level_1_bonus',20),
('vip_level_2_bonus',50),
('vip_level_3_bonus',100),
('ads_level_1_bonus',10),
('ads_level_2_bonus',25),
('ads_level_3_bonus',50),
('ads_level_4_bonus',80);
