import sqlite3

db_path = "data/map_styles.db"
conn = sqlite3.connect(db_path)
conn.execute("PRAGMA foreign_keys = ON;")

# Test 1: Insert invalid style_id into map_style_tiles
try:
    conn.execute(
        "INSERT INTO map_style_tiles (style_id, tile_type_id, tile_type_name, texture_filename, normal_filename, base_color_fallback) "
        "VALUES ('NON_EXISTENT_STYLE', 1, 'FLOOR', 'floor.png', 'floor_normal.png', '#000000');"
    )
    print("FAIL: FK did not reject invalid style_id in map_style_tiles")
except sqlite3.IntegrityError as e:
    print("PASS: FK rejected invalid style_id:", e)

# Test 2: Insert invalid style_id into map_style_props
try:
    conn.execute(
        "INSERT INTO map_style_props (prop_id, style_id, prop_name_vi, prop_name_en, sprite_key, sprite_path, spawn_weight, placement_rule) "
        "VALUES ('PROP_FAIL', 'NON_EXISTENT_STYLE', 'Test', 'Test', 'prop_test', 'props.png', 0.5, 'ANY_FLOOR');"
    )
    print("FAIL: FK did not reject invalid style_id in map_style_props")
except sqlite3.IntegrityError as e:
    print("PASS: FK rejected invalid style_id in props:", e)

# Test 3: Check check constraints on biome_code (must be between 1 and 255)
try:
    conn.execute(
        "INSERT INTO map_styles (style_id, biome_code, name_vi, name_en, theme_category, theme_category_name, description, floor_color_hex, wall_color_hex, path_color_hex, liquid_color_hex, ambient_light_hex, asset_dir, monster_family) "
        "VALUES ('FAIL_STYLE', 0, 'Test', 'Test', 'HOANG_DA_DA_NGOAI', 'Test', 'Desc', '#000000', '#000000', '#000000', '#000000', '#000000', 'dir', 'mob');"
    )
    print("FAIL: Check constraint did not reject biome_code 0")
except sqlite3.IntegrityError as e:
    print("PASS: Check constraint rejected biome_code 0:", e)

conn.close()
