CREATE TABLE IF NOT EXISTS order_assignments (
    id INT AUTO_INCREMENT PRIMARY KEY,
    siparis_no VARCHAR(50) NOT NULL,
    item_id VARCHAR(100) NOT NULL,
    variant_text VARCHAR(100) DEFAULT '',
    unit_index INT NOT NULL DEFAULT 1,
    assigned_store_id INT NOT NULL,
    status VARCHAR(50) NOT NULL DEFAULT 'assigned', -- 'assigned', 'checked_ok', 'checked_damaged', 'shipped'
    notes TEXT DEFAULT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    KEY idx_siparis_no (siparis_no),
    KEY idx_store_status (assigned_store_id, status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS order_deliveries (
    id INT AUTO_INCREMENT PRIMARY KEY,
    siparis_no VARCHAR(50) NOT NULL,
    package_photo_path VARCHAR(255) DEFAULT NULL,
    invoice_pdf_path VARCHAR(255) DEFAULT NULL,
    label_pdf_path VARCHAR(255) DEFAULT NULL,
    status VARCHAR(50) NOT NULL DEFAULT 'preparing', -- 'preparing', 'shipped', 'delivered'
    shipped_at TIMESTAMP NULL DEFAULT NULL,
    delivered_at TIMESTAMP NULL DEFAULT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_siparis_no (siparis_no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
