import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps" / "api"))

from app.api.routes.assets import _apply_asset_review_status

from packages.domain import Asset, AssetStatus


def test_apply_asset_review_status_preserves_existing_metadata():
    asset = Asset.create(
        project_id="project-1",
        library_id="library-1",
        name="video.mp4",
        storage_key="uploads/video.mp4",
        mime_type="video/mp4",
        file_size=1024,
        status=AssetStatus.READY,
        metadata={"generation_use_count": 2},
    )

    _apply_asset_review_status(asset, "approved")

    assert asset.metadata["generation_use_count"] == 2
    assert asset.metadata["review_status"] == "approved"
