"""GeneratedVideo 生成视频领域实体单测."""

import pytest

from packages.domain.generated_video import GeneratedVideo


class TestGeneratedVideoCreate:
    def test_create_normal(self):
        video = GeneratedVideo.create(
            project_id="proj1",
            generation_task_id="task1",
            name="我的视频",
            file_url="https://example.com/video.mp4",
            file_size=1024000,
            duration=30.5,
            width=1920,
            height=1080,
            fps=30.0,
        )
        assert video.id
        assert video.project_id == "proj1"
        assert video.generation_task_id == "task1"
        assert video.name == "我的视频"
        assert video.file_url == "https://example.com/video.mp4"
        assert video.file_size == 1024000
        assert video.duration == 30.5
        assert video.width == 1920
        assert video.height == 1080
        assert video.fps == 30.0
        assert video.status == "completed"
        assert video.review_status == "pending_review"
        assert video.is_duplicate is False
        assert video.generation_params == {}

    def test_create_strips_whitespace(self):
        video = GeneratedVideo.create(
            project_id="  proj1  ",
            generation_task_id="  task1  ",
            name="  我的视频  ",
            file_url="  https://example.com/video.mp4  ",
            user_id="  user1  ",
        )
        assert video.project_id == "proj1"
        assert video.generation_task_id == "task1"
        assert video.name == "我的视频"
        assert video.file_url == "https://example.com/video.mp4"
        assert video.user_id == "user1"

    def test_create_empty_project_id_raises(self):
        with pytest.raises(ValueError, match="project_id cannot be empty"):
            GeneratedVideo.create(
                project_id="",
                generation_task_id="task1",
                name="视频",
                file_url="https://example.com/v.mp4",
            )

    def test_create_whitespace_project_id_raises(self):
        with pytest.raises(ValueError, match="project_id cannot be empty"):
            GeneratedVideo.create(
                project_id="   ",
                generation_task_id="task1",
                name="视频",
                file_url="https://example.com/v.mp4",
            )

    def test_create_empty_generation_task_id_raises(self):
        with pytest.raises(ValueError, match="generation_task_id cannot be empty"):
            GeneratedVideo.create(
                project_id="proj1",
                generation_task_id="",
                name="视频",
                file_url="https://example.com/v.mp4",
            )

    def test_create_empty_name_raises(self):
        with pytest.raises(ValueError, match="name cannot be empty"):
            GeneratedVideo.create(
                project_id="proj1",
                generation_task_id="task1",
                name="",
                file_url="https://example.com/v.mp4",
            )

    def test_create_empty_file_url_raises(self):
        with pytest.raises(ValueError, match="file_url cannot be empty"):
            GeneratedVideo.create(
                project_id="proj1",
                generation_task_id="task1",
                name="视频",
                file_url="",
            )

    def test_create_default_values(self):
        video = GeneratedVideo.create(
            project_id="proj1",
            generation_task_id="task1",
            name="视频",
            file_url="https://example.com/v.mp4",
        )
        assert video.file_size == 0
        assert video.duration == 0.0
        assert video.width == 0
        assert video.height == 0
        assert video.fps == 0.0
        assert video.thumbnail_url is None
        assert video.user_id == ""
        assert video.generation_params == {}

    def test_create_with_generation_params(self):
        params = {"mode": "pip", "resolution": "1080p"}
        video = GeneratedVideo.create(
            project_id="proj1",
            generation_task_id="task1",
            name="视频",
            file_url="https://example.com/v.mp4",
            generation_params=params,
        )
        assert video.generation_params == params

    def test_create_none_generation_params(self):
        video = GeneratedVideo.create(
            project_id="proj1",
            generation_task_id="task1",
            name="视频",
            file_url="https://example.com/v.mp4",
            generation_params=None,
        )
        assert video.generation_params == {}

    def test_create_unique_ids(self):
        v1 = GeneratedVideo.create(
            project_id="proj1", generation_task_id="t1", name="v1", file_url="https://a.com/1.mp4"
        )
        v2 = GeneratedVideo.create(
            project_id="proj1", generation_task_id="t2", name="v2", file_url="https://a.com/2.mp4"
        )
        assert v1.id != v2.id
