"""EditTemplate 剪辑模板领域实体单测."""

import pytest

from packages.domain.edit_template import EditTemplate, EditTemplateStatus
from packages.domain.editing_mode import EditingMode


class TestEditTemplateStatus:
    def test_values(self):
        assert EditTemplateStatus.ACTIVE.value == "active"
        assert EditTemplateStatus.INACTIVE.value == "inactive"


class TestEditTemplateCreate:
    def test_create_default(self):
        tpl = EditTemplate.create(name="测试模板")
        assert tpl.id
        assert tpl.name == "测试模板"
        assert tpl.editing_mode == EditingMode.ONE_TAKE.value
        assert tpl.status == EditTemplateStatus.ACTIVE
        assert tpl.version == 1
        assert tpl.config == {}
        assert tpl.description == ""
        assert tpl.sort_weight == 0

    def test_create_strips_name(self):
        tpl = EditTemplate.create(name="  我的模板  ")
        assert tpl.name == "我的模板"

    def test_create_empty_name_raises(self):
        with pytest.raises(ValueError, match="模板名称不能为空"):
            EditTemplate.create(name="")

    def test_create_whitespace_name_raises(self):
        with pytest.raises(ValueError, match="模板名称不能为空"):
            EditTemplate.create(name="   ")

    def test_create_valid_editing_modes(self):
        for mode in EditingMode:
            tpl = EditTemplate.create(name=f"模板_{mode.value}", editing_mode=mode.value)
            assert tpl.editing_mode == mode.value

    def test_create_invalid_editing_mode_raises(self):
        with pytest.raises(ValueError, match="无效的 editing_mode"):
            EditTemplate.create(name="模板", editing_mode="invalid_mode")

    def test_create_empty_editing_mode_defaults_to_one_take(self):
        tpl = EditTemplate.create(name="模板", editing_mode="")
        assert tpl.editing_mode == EditingMode.ONE_TAKE.value

    def test_create_with_config(self):
        config = {"key": "value"}
        tpl = EditTemplate.create(name="模板", config=config)
        assert tpl.config == config

    def test_create_none_config_defaults_to_empty(self):
        tpl = EditTemplate.create(name="模板", config=None)
        assert tpl.config == {}

    def test_create_with_custom_status(self):
        tpl = EditTemplate.create(name="模板", status=EditTemplateStatus.INACTIVE)
        assert tpl.status == EditTemplateStatus.INACTIVE

    def test_create_unique_ids(self):
        t1 = EditTemplate.create(name="t1")
        t2 = EditTemplate.create(name="t2")
        assert t1.id != t2.id
