# Generated by qodo Gen

import pytest
from lfx.schema.table import Column, FormatterType


class TestColumn:
    # Creating a Column instance without display_name sets it to the name
    def test_create_column_without_display_name(self):
        column = Column(name="test_column")
        assert column.display_name == "test_column"

    # Creating a Column instance with valid formatter values
    def test_create_column_with_valid_formatter(self):
        column = Column(display_name="Test Column", name="test_column", formatter="date")
        assert column.formatter == FormatterType.date

    # Formatter is set based on provided formatter value
    def test_formatter_set_based_on_value(self):
        column = Column(display_name="Test Column", name="test_column", formatter="int")
        assert column.formatter == FormatterType.number

    # Default values for sortable and filterable are set to True
    def test_default_sortable_filterable(self):
        column = Column(display_name="Test Column", name="test_column")
        assert column.sortable is True
        assert column.filterable is True

    # Ensure formatter field is correctly set when provided a FormatterType
    def test_formatter_explicitly_set_to_enum(self):
        column = Column(display_name="Date Column", name="date_column", formatter=FormatterType.date)
        assert column.formatter == FormatterType.date

    # Invalid formatter raises ValueError
    def test_invalid_formatter_raises_value_error(self):
        with pytest.raises(ValueError, match="'invalid' is not a valid FormatterType"):
            Column(display_name="Invalid Column", name="invalid_column", formatter="invalid")

    # Formatter is None when not provided
    def test_formatter_none_when_not_provided(self):
        column = Column(display_name="Test Column", name="test_column")
        assert column.formatter is None

    # Description and default can be set
    def test_description_and_default(self):
        column = Column(
            display_name="Test Column", name="test_column", description="A test column", default="default_value"
        )
        assert column.description == "A test column"
        assert column.default == "default_value"

    def test_create_with_type_instead_of_formatter(self):
        column = Column(display_name="Test Column", name="test_column", type="date")
        assert column.formatter == FormatterType.date

    # Test load_from_db functionality
    def test_column_load_from_db_default_false(self):
        """Test that load_from_db defaults to False."""
        column = Column(name="test_column")
        assert column.load_from_db is False

    def test_column_load_from_db_can_be_set_true(self):
        """Test that load_from_db can be explicitly set to True."""
        column = Column(name="test_column", load_from_db=True)
        assert column.load_from_db is True

    def test_column_load_from_db_with_default_value(self):
        """Test that load_from_db works with default values."""
        column = Column(name="username", display_name="Username", default="admin", load_from_db=True)
        assert column.load_from_db is True
        assert column.default == "admin"

    def test_column_load_from_db_false_uses_static_default(self):
        """Test that when load_from_db is False, static defaults are used."""
        column = Column(name="role", display_name="User Role", default="user", load_from_db=False)
        assert column.load_from_db is False
        assert column.default == "user"

    def test_multiple_columns_mixed_load_from_db(self):
        """Test creating multiple columns with different load_from_db settings."""
        columns = [
            Column(name="username", load_from_db=True, default="admin"),
            Column(name="email", load_from_db=True, default="user@example.com"),
            Column(name="role", load_from_db=False, default="user"),
            Column(name="active", load_from_db=False, default=True, type="boolean"),
        ]

        # Check load_from_db settings
        assert columns[0].load_from_db is True
        assert columns[1].load_from_db is True
        assert columns[2].load_from_db is False
        assert columns[3].load_from_db is False

        # Check defaults are preserved
        assert columns[0].default == "admin"
        assert columns[1].default == "user@example.com"
        assert columns[2].default == "user"
        assert columns[3].default is True
