from db.canonical_attributes import normalize_depth_option_label
from db.channel_remote_attributes import list_all_master_attribute_values
from db.models import MasterProduct, MasterProductAttributeValue


def test_normalize_depth_option_label_fractions_and_inches():
    assert normalize_depth_option_label('1/4"') == "0.25"
    assert normalize_depth_option_label("3/4") == "0.75"
    assert normalize_depth_option_label('1 1/8"') == "1.125"
    assert normalize_depth_option_label("24") == "24"
    assert normalize_depth_option_label("12") == "12"


def test_list_all_master_attribute_values_depth_uses_source_codes(catalog_intent_session):
    session = catalog_intent_session
    product = MasterProduct(
        sku="ACH-B12",
        name="Base",
        row_hash="d1",
        is_active=True,
    )
    session.add(product)
    session.flush()
    session.add_all(
        [
            MasterProductAttributeValue(
                product_id=product.id,
                sku=product.sku,
                attribute_code="assembled_depth",
                value="24",
            ),
            MasterProductAttributeValue(
                product_id=product.id,
                sku=product.sku,
                attribute_code="variation_depth_in",
                value='3/4"',
            ),
        ]
    )
    other = MasterProduct(sku="ACH-B15", name="Base 15", row_hash="d2", is_active=True)
    session.add(other)
    session.flush()
    session.add(
        MasterProductAttributeValue(
            product_id=other.id,
            sku=other.sku,
            attribute_code="variation_depth_in",
            value="12",
        )
    )
    session.flush()

    values = list_all_master_attribute_values(session, "depth")
    assert "24" in values
    assert "12" in values
    assert "0.75" in values
