CREATE TABLE IF NOT EXISTS vehicle_hydrogen_tank_capacity (
    vin VARCHAR(64) NOT NULL,
    source_vehicle_id BIGINT NOT NULL,
    source_model_id BIGINT NULL,
    plate_number VARCHAR(50) NOT NULL DEFAULT '',
    brand_name VARCHAR(500) NOT NULL DEFAULT '',
    model_name VARCHAR(500) NOT NULL DEFAULT '',
    tank_capacity_l DECIMAL(12,2) NOT NULL,
    active TINYINT(1) NOT NULL DEFAULT 1,
    source_updated_at DATETIME NULL,
    synced_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    PRIMARY KEY (vin),
    INDEX idx_hydrogen_capacity_model (source_model_id),
    INDEX idx_hydrogen_capacity_active (active,vin)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE vehicle_open_hydrogen_stream_state
    ADD COLUMN tank_capacity_l DECIMAL(12,2) NULL AFTER abnormal_drop_count,
    ADD COLUMN first_pressure_mpa DECIMAL(10,3) NULL AFTER tank_capacity_l,
    ADD COLUMN last_pressure_mpa DECIMAL(10,3) NULL AFTER first_pressure_mpa,
    ADD COLUMN first_temperature_c DECIMAL(10,3) NULL AFTER last_pressure_mpa,
    ADD COLUMN last_temperature_c DECIMAL(10,3) NULL AFTER first_temperature_c,
    ADD COLUMN calculation_method VARCHAR(32) NOT NULL DEFAULT 'PRESSURE_NIST' AFTER last_temperature_c;

CREATE INDEX idx_hydrogen_capacity_sync
    ON vehicle_hydrogen_tank_capacity (synced_at,active);
