-- Fixtures for the DeD building search endpoint.
-- Loaded last (08_ prefix) because it rebuilds mv_ded_building_search from everything above.

-- Building that is discarded in ENO - it must never appear in search results even though it has a
-- name, an address and a consumption point.
INSERT INTO eno_budova (gid, zdroj, nazev, oznaceni, platnost_od) VALUES
	('GIDDEL1', 'mhmp', 'ZŠ Vyřazená', 'ZŠV', '2019-01-01');

INSERT INTO eno_adresa (gid, gid_typ, poradi, zdroj, id, popis, hlavni) VALUES
	('GIDDEL1', 'budova', 1, 'mhmp', 601, 'Vyřazená 1, 100 00 Praha 10', true);

INSERT INTO eno_vyrazeno (gid, gid_typ, zdroj) VALUES
	('GIDDEL1', 'budova', 'mhmp');

-- Geometry in S-JTSK (EPSG 5514), the ENO default. GID100 has two polygons so the collected
-- geometry is a MultiPolygon and the bbox has to span both.
INSERT INTO eno_geometrie (gid, zdroj, poradi, id_organizace, uzivatelsky_zakres, zakres, epsg_code) VALUES
	('GID100', 'mhmp', 1, 1, false,
		'POLYGON((-743100 -1043100, -743050 -1043100, -743050 -1043050, -743100 -1043050, -743100 -1043100))', '5514'),
	('GID100', 'mhmp', 2, 1, false,
		'POLYGON((-743050 -1043050, -743000 -1043050, -743000 -1043000, -743050 -1043000, -743050 -1043050))', '5514'),
	-- Unparsable geometry must degrade to NULL instead of aborting the index refresh.
	('GID200', 'mhmp', 1, 1, false, 'THIS IS NOT WKT', '5514');

REFRESH MATERIALIZED VIEW mv_ded_building_search;
