"""
Tests for asset_path mixin module
"""

import pytest
import os
from unittest.mock import Mock


class TestAssetPathMixin:
    """Tests for AssetPathMixin class"""

    def test_resolve_asset_path_empty_path(self, tmp_path):
        """Test resolve_asset_path with empty path returns None"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock()
                self.project.folder_path = str(tmp_path)

        obj = TestClass()
        assert obj.resolve_asset_path("") is None
        assert obj.resolve_asset_path(None) is None

    def test_resolve_asset_path_absolute_exists(self, tmp_path):
        """Test resolve_asset_path with existing absolute path"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        # Create a test file
        test_file = tmp_path / "test_image.jpg"
        test_file.write_text("test")

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock()
                self.project.folder_path = str(tmp_path)

        obj = TestClass()
        result = obj.resolve_asset_path(str(test_file))

        assert result == str(test_file)

    def test_resolve_asset_path_absolute_not_exists(self, tmp_path):
        """Test resolve_asset_path with non-existing absolute path"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock()
                self.project.folder_path = str(tmp_path)

        obj = TestClass()
        result = obj.resolve_asset_path("/nonexistent/path/image.jpg")

        assert result is None

    def test_resolve_asset_path_relative_exists(self, tmp_path):
        """Test resolve_asset_path with existing relative path"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        # Create assets folder and test file
        assets_dir = tmp_path / "assets"
        assets_dir.mkdir()
        test_file = assets_dir / "photo.jpg"
        test_file.write_text("test")

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock()
                self.project.folder_path = str(tmp_path)

        obj = TestClass()
        result = obj.resolve_asset_path("assets/photo.jpg")

        assert result == str(test_file)

    def test_resolve_asset_path_relative_not_exists(self, tmp_path):
        """Test resolve_asset_path with non-existing relative path"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock()
                self.project.folder_path = str(tmp_path)

        obj = TestClass()
        result = obj.resolve_asset_path("assets/nonexistent.jpg")

        assert result is None

    def test_resolve_asset_path_no_project_folder(self):
        """Test resolve_asset_path when project folder is not available"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = None

        obj = TestClass()
        result = obj.resolve_asset_path("assets/photo.jpg")

        assert result is None

    def test_get_asset_full_path_with_project(self, tmp_path):
        """Test get_asset_full_path returns correct path"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock()
                self.project.folder_path = str(tmp_path)

        obj = TestClass()
        result = obj.get_asset_full_path("assets/photo.jpg")

        expected = os.path.join(str(tmp_path), "assets/photo.jpg")
        assert result == expected

    def test_get_asset_full_path_no_project(self):
        """Test get_asset_full_path without project returns None"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = None

        obj = TestClass()
        result = obj.get_asset_full_path("assets/photo.jpg")

        assert result is None

    def test_get_asset_full_path_empty_path(self, tmp_path):
        """Test get_asset_full_path with empty path returns None"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock()
                self.project.folder_path = str(tmp_path)

        obj = TestClass()
        assert obj.get_asset_full_path("") is None
        assert obj.get_asset_full_path(None) is None

    def test_get_project_folder_with_project(self, tmp_path):
        """Test _get_project_folder returns project folder"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock()
                self.project.folder_path = str(tmp_path)

        obj = TestClass()
        result = obj._get_project_folder()

        assert result == str(tmp_path)

    def test_get_project_folder_no_project(self):
        """Test _get_project_folder without project returns None"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            pass

        obj = TestClass()
        result = obj._get_project_folder()

        assert result is None

    def test_get_project_folder_project_without_folder_path(self):
        """Test _get_project_folder with project missing folder_path"""
        from pyPhotoAlbum.mixins.asset_path import AssetPathMixin

        class TestClass(AssetPathMixin):
            def __init__(self):
                self.project = Mock(spec=[])  # No folder_path attribute

        obj = TestClass()
        result = obj._get_project_folder()

        assert result is None
