"""EditPlan 剪辑计划领域实体单测."""

import pytest

from packages.domain.edit_plan import EditPlan, EditPlanStatus


class TestEditPlanStatus:
    def test_values(self):
        assert EditPlanStatus.DRAFT.value == "draft"
        assert EditPlanStatus.EDITING.value == "editing"
        assert EditPlanStatus.RENDERING.value == "rendering"
        assert EditPlanStatus.COMPLETED.value == "completed"
        assert EditPlanStatus.FAILED.value == "failed"

    def test_is_str(self):
        assert isinstance(EditPlanStatus.DRAFT, str)


class TestEditPlanCreate:
    def test_create_normal(self):
        plan = EditPlan.create(template_id="tmpl1", name="我的剪辑计划")
        assert plan.id
        assert plan.template_id == "tmpl1"
        assert plan.name == "我的剪辑计划"
        assert plan.status == EditPlanStatus.DRAFT
        assert plan.total_duration == 0.0
        assert plan.config == {}

    def test_create_strips_whitespace(self):
        plan = EditPlan.create(
            template_id="  tmpl1  ",
            name="  我的计划  ",
            source_edit_plan_id="  src1  ",
            project_id="  proj1  ",
            created_by_user_id="  user1  ",
        )
        assert plan.template_id == "tmpl1"
        assert plan.name == "我的计划"
        assert plan.source_edit_plan_id == "src1"
        assert plan.project_id == "proj1"
        assert plan.created_by_user_id == "user1"

    def test_create_empty_name_raises(self):
        with pytest.raises(ValueError, match="计划名称不能为空"):
            EditPlan.create(template_id="tmpl1", name="")

    def test_create_whitespace_name_raises(self):
        with pytest.raises(ValueError, match="计划名称不能为空"):
            EditPlan.create(template_id="tmpl1", name="   ")

    def test_create_empty_template_id_raises(self):
        with pytest.raises(ValueError, match="template_id 不能为空"):
            EditPlan.create(template_id="", name="计划")

    def test_create_whitespace_template_id_raises(self):
        with pytest.raises(ValueError, match="template_id 不能为空"):
            EditPlan.create(template_id="   ", name="计划")

    def test_create_with_config(self):
        config = {"resolution": "1080p", "fps": 30}
        plan = EditPlan.create(
            template_id="tmpl1",
            name="计划",
            config=config,
            total_duration=30.5,
        )
        assert plan.config == config
        assert plan.total_duration == 30.5

    def test_create_none_config_defaults_to_empty(self):
        plan = EditPlan.create(template_id="tmpl1", name="计划", config=None)
        assert plan.config == {}

    def test_create_unique_ids(self):
        p1 = EditPlan.create(template_id="t1", name="p1")
        p2 = EditPlan.create(template_id="t1", name="p2")
        assert p1.id != p2.id
