DROP MATERIALIZED VIEW IF EXISTS mv_ded_building_search;

DROP FUNCTION IF EXISTS f_ded_safe_geom(text, varchar);

-- Restore v_enapo_building_detail to the pre-search definition (migration 20260807090000), dropping the
-- ENO lookup columns this migration added. The view is dropped and recreated rather than replaced because
-- CREATE OR REPLACE VIEW cannot remove columns; the dependent mv_ded_building_search is already gone above.
DROP VIEW IF EXISTS v_enapo_building_detail;

CREATE VIEW v_enapo_building_detail AS
SELECT DISTINCT ON (b.gid)
	b.gid,
	b.zdroj,
	b.nazev,
	b.oznaceni,
	b.druh_vytapeni,
	b.pripojka_elektro,
	b.pripojka_voda,
	b.pripojka_kanalizace,
	b.budova_rozdelena_byt_nebyt,
	b.celkova_plocha_budova,
	b.celkova_plocha_byt_budova,
	b.celkova_plocha_nebyt_budova,
	b.zastavena_plocha,
	b.obestaveny_prostor,
	b.pocet_byt,
	b.pocet_nebyt_budova,
	b.pocet_nadzem_podlazi,
	b.pocet_podzem_podlazi,
	b.pocet_podkrovi,
	b.vytah,
	b.czcc,
	b.id_cuzk,
	b.id_objekt,
	b.kod_vyuziti,
	b.nazev_vyuziti,
	b.kod_ochrana,
	b.nazev_ochrana,
	b.platnost_od
FROM eno_budova b
ORDER BY b.gid, b.zdroj;
