-- 064_project_premises_layer_tooltip.sql
-- The Project Premises tooltip names a colour the layer no longer uses.
-- (docs/2026-08-31-project-premises-map-layer.md, Decision 1)
--
-- 063 registered the layer with a tooltip that reads "teal is counted by a sub-project".
-- That style is now a pale purple: the teal (--gl-ok, #0E6B62) read as plain green
-- against the beige basemap (Dave, 2026-09-01), and the three levels moved to one hue at
-- three weights, which is what they are. The tooltip is the layer's only legend, so a
-- colour word in it is load-bearing rather than decorative and cannot be left wrong.
--
-- A MIGRATION FOR A STRING, deliberately. 063 is applied, and applied migrations are
-- immutable — editing its tooltip in place would leave every database that has already
-- run it showing the old copy with no record of why. Changing public.map_layers content
-- through a numbered migration is the established path here (030, 041, 051 and 055 all
-- do it).
--
-- The wording drops the hue names for the two ends and keeps only what the ramp cannot
-- say for itself. "Filled purple" versus "paler" versus "outlined" is the actual visual
-- distinction, and it stays true if the exact hex moves again.

DO $$
DECLARE
    v_n integer;
BEGIN
    UPDATE public.map_layers
       SET tooltip = 'Premises across this project and its hierarchy. Solid is counted here, paler is counted by a sub-project, outlined is counted above.'
     WHERE layer_name     = 'projectPremises'
       AND database_schema = 'projects'
       AND database_table  = 'vw_project_premises_map';
    GET DIAGNOSTICS v_n = ROW_COUNT;

    -- 025's map-layer UPDATE matched nothing and reported success, which is how two
    -- opportunity layers ended up permanently empty. Every statement asserts its count.
    IF v_n <> 1 THEN
        RAISE EXCEPTION '064: tooltip update matched % row(s), expected 1 - apply 063 first', v_n;
    END IF;
END $$;

-- == Verify =================================================================

DO $$
DECLARE
    v_tip text;
BEGIN
    SELECT tooltip INTO v_tip
      FROM public.map_layers
     WHERE layer_name = 'projectPremises';

    IF v_tip LIKE '%teal%' OR v_tip LIKE '%green%' THEN
        RAISE EXCEPTION '064: tooltip still names the old colour: %', v_tip;
    END IF;

    -- The tooltip is the only thing on screen that says what the three styles mean, so
    -- it has to still describe three of them.
    IF v_tip NOT LIKE '%sub-project%' OR v_tip NOT LIKE '%above%' THEN
        RAISE EXCEPTION '064: tooltip no longer describes all three levels: %', v_tip;
    END IF;
END $$;
