-- Mock GID mapping (link_source = 'mock'); real rows will come from the data-team dbt output later
INSERT INTO enapo_gid_mapping (place_id, id_type, commodity, gid, is_first_gid, link_source, valid_from, valid_to) VALUES
	('27ZG100Z0000192O', 'eic', 'gas', 'GID100', true, 'mock', '2019-12-05', NULL),
	('27ZG100Z0000192O', 'eic', 'gas', 'GID200', false, 'mock', '2019-12-05', NULL),
	('859182400000000001', 'ean', 'electricity', 'GID100', true, 'mock', '2022-07-28', NULL),
	('859182400000000002', 'ean', 'electricity', 'GID100', true, 'mock', '2019-12-05', '2025-01-01'),
	('859182400000000003', 'ean', 'electricity', 'GID999', true, 'mock', '2022-07-28', NULL);

-- PRE metadata history: two months for the active EAN (the newer one must win)
INSERT INTO enapo_pre_metadata_history (ean, "year", "month", month_name, days_in_stored_month, consumption_point,
	address, location_type, company_name, company_id, tarif_type, tarif_1t2t, phases, circuit_breaker, type_b_meter,
	meter_replaced, created_at, updated_at) VALUES
	('859182400000000001', 2026, 5, 'květen', 31, 'OM Testovací 123',
		'Testovací 123/4, Praha 10', 'škola', 'Hlavní město Praha', '00064581', 'C02d', '1T', '3', '3x100A', 'ano',
		'53435572', '2026-06-05 00:00:00', NULL),
	('859182400000000001', 2026, 6, 'červen', 30, 'OM Testovací 123',
		'Testovací 123/4, Praha 10', 'škola', 'Hlavní město Praha', '00064581', 'C02d', '1T', '3', '3x125A', 'ano',
		'2026-06-19|53435572|54292510', '2026-07-05 00:00:00', NULL);

-- PPAS distribution invoices: an older valid one, a newer canceled one (must be skipped)
INSERT INTO enapo_ppas_distribution_invoice (id, preceding_id, customer_id, customer_company_id, customer_name,
	customer_contract_account_id, customer_address_street, customer_address_house_number, customer_address_house_org_number,
	customer_address_city, customer_address_city_part, customer_address_post_code, customer_address_country,
	customer_address_ruian_id, facts_doc_date, facts_net_date, facts_billing_transaction, facts_to_pay_amount,
	facts_currency, facts_price_brutto, is_canceled, canceled_reason) VALUES
	('DI-2026-001', NULL, 'CUST-1', '00064581', 'Hlavní město Praha',
		'CA-1', 'Mariánské náměstí', '2', NULL,
		'Praha', 'Staré Město', '11000', 'CZ',
		22349995, '2026-03-15', '2026-03-29', 'FAKTURACE', 15250.50,
		'CZK', 18453.11, false, NULL),
	('DI-2026-002', 'DI-2026-001', 'CUST-1', '00064581', 'Hlavní město Praha',
		'CA-1', 'Mariánské náměstí', '2', NULL,
		'Praha', 'Staré Město', '11000', 'CZ',
		22349995, '2026-05-20', '2026-06-03', 'STORNO', -15250.50,
		'CZK', -18453.11, true, 'oprava odečtu');

-- Two installations on the valid invoice: only the first one is mapped to a GID, the second exists
-- to prove devices/prices are scoped by place_id and do not leak across consumption points.
INSERT INTO enapo_ppas_distribution_installation (invoice_id, customer_id, place_id, eic, billing_class,
	measurement_type, contract_contract_id, contract_move_in_date, contract_move_out_date, tdd_class,
	address_street, address_house_number, address_house_org_number, address_city, address_city_part,
	address_post_code, address_country, address_ruian_id) VALUES
	('DI-2026-001', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
		'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
		'Testovací', '123', '4', 'Praha', 'Praha 10',
		'10000', 'CZ', 22349996),
	('DI-2026-001', 'CUST-1', '10101999', '27ZG100Z0000999O', 'MO',
		'C', 'SML-9', '2019-12-05', '9999-12-31', 'DOM4',
		'Jiná', '9', NULL, 'Praha', 'Praha 9',
		'19000', 'CZ', 22349999),
	('DI-2026-002', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
		'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
		'Testovací', '123', '4', 'Praha', 'Praha 10',
		'10000', 'CZ', 22349996);

INSERT INTO enapo_ppas_distribution_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
	"type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
	volume_coefficient, combustion_heat, normometers_nm3) VALUES
	('PLYN-001', 'DI-2026-001', '10101325', '2025-03-01', '2026-02-28', 'G4', 'plynoměr',
		'řádný', 10250.0, 11930.0, 1680.0, 'm3', 'dálkový', 17750.4,
		1.0043, 10.55, 1687.2),
	('PLYN-999', 'DI-2026-001', '10101999', '2025-03-01', '2026-02-28', 'G4', 'plynoměr',
		'řádný', 500.0, 700.0, 200.0, 'm3', 'dálkový', 2113.1,
		1.0043, 10.55, 200.9);

INSERT INTO enapo_ppas_distribution_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
	description, price_group, quantity, unit, unit_price, time_slot, price_netto, price_type, currency, tax_rate) VALUES
	('DI-2026-001', 'CUST-1', '10101325', '2025-03-01', '2026-02-28', 'distribuce', 'Distribuce plynu',
		'D1', 17750.4, 'kWh', 0.35, 0.19355, 6212.64, 'variabilní', 'CZK', 21.0),
	('DI-2026-001', 'CUST-1', '10101999', '2025-03-01', '2026-02-28', 'distribuce', 'Distribuce plynu',
		'D1', 2113.1, 'kWh', 0.35, NULL, 739.59, 'variabilní', 'CZK', 21.0);

-- PPAS commercial invoices: a valid one and a newer canceled one (must be skipped)
INSERT INTO enapo_ppas_commercial_invoice (id, preceding_id, customer_id, customer_company_id, customer_name,
	customer_contract_account_id, customer_address_street, customer_address_house_number, customer_address_house_org_number,
	customer_address_city, customer_address_city_part, customer_address_post_code, customer_address_country,
	customer_address_ruian_id, facts_doc_date, facts_net_date, facts_billing_transaction, facts_to_pay_amount,
	facts_currency, facts_price_brutto, is_canceled, canceled_reason) VALUES
	('CI-2026-001', NULL, 'CUST-1', '00064581', 'Hlavní město Praha',
		'CA-1', 'Mariánské náměstí', '2', NULL,
		'Praha', 'Staré Město', '11000', 'CZ',
		22349995, '2026-04-10', '2026-04-24', 'FAKTURACE', 28900.00,
		'CZK', 34969.00, false, NULL),
	('CI-2026-002', 'CI-2026-001', 'CUST-1', '00064581', 'Hlavní město Praha',
		'CA-1', 'Mariánské náměstí', '2', NULL,
		'Praha', 'Staré Město', '11000', 'CZ',
		22349995, '2026-06-01', '2026-06-15', 'STORNO', -28900.00,
		'CZK', -34969.00, true, 'reklamace');

INSERT INTO enapo_ppas_commercial_invoice_installations (invoice_id, customer_id, place_id, eic, billing_class,
	measurement_type, contract_contract_id, contract_move_in_date, contract_move_out_date, tdd_class,
	address_street, address_house_number, address_house_org_number, address_city, address_city_part,
	address_post_code, address_country, address_ruian_id) VALUES
	('CI-2026-001', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
		'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
		'Testovací', '123', '4', 'Praha', 'Praha 10',
		'10000', 'CZ', 22349996),
	('CI-2026-002', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
		'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
		'Testovací', '123', '4', 'Praha', 'Praha 10',
		'10000', 'CZ', 22349996);

INSERT INTO enapo_ppas_commercial_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
	"type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
	volume_coefficient, combustion_heat, normometers_nm3) VALUES
	('PLYN-001', 'CI-2026-001', '10101325', '2025-03-01', '2026-02-28',
		'G4', 'plynoměr', 'řádný', 10250.0, 11930.0, 1680.0, 'm3', 'dálkový', 17750.4,
		1.0043, 10.55, 1687.2);

INSERT INTO enapo_ppas_commercial_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
	description, price_group, quantity, unit, unit_price, time_slot, price_netto, price_type, currency, tax_rate) VALUES
	('CI-2026-001', 'CUST-1', '10101325', '2025-03-01', '2026-02-28', 'komodita',
		'Dodávka plynu', 'K1', 17750.4, 'kWh', 1.45, NULL, 25738.08, 'variabilní', 'CZK', 21.0);

-- Porsenna (e-manazer): buildings, devices (incl. heat/water and a sub-meter), yearly consumption.
-- Device types and tenant naming mirror real Porsenna data (electricity_meter/heat_meter/water_meter, tenant prague-7).
INSERT INTO enapo_porsenna_buildings (source, id, name, street, house_number, street_number, city, postcode, gid) VALUES
	('prague-7', 1, 'ZŠ Testovací (e-manažer)', 'Testovací', '123', '4', 'Praha 10', '10000', 'GID100'),
	('prague-7', 2, 'Vrátnice Kundratka', 'Kundratka', '19', NULL, 'Praha 8', '18000', 'GIDPOR1');

INSERT INTO enapo_porsenna_devices (source, id, building_id, parent_device_id, "level", "type", name,
	measurement_target, disabled_at, disable_reason_id, show_in_output, identifier, supply_point_number,
	meter_number, identification_gid) VALUES
	('prague-7', '11111111-1111-1111-1111-111111111111', 1, NULL, 'main', 'electricity_meter', 'Hlavní elektroměr',
		'consumption', NULL, NULL, true, '859182400000000001', 'OP-100', 'EL-123', 'GID100'),
	('prague-7', '22222222-2222-2222-2222-222222222222', 1, NULL, 'main', 'heat_meter', 'Předávací stanice CZT',
		'consumption', NULL, NULL, true, '40001234', 'OP-101', 'TEP-77', 'GID100'),
	('prague-7', '33333333-3333-3333-3333-333333333333', 1, NULL, 'main', 'water_meter', 'Hlavní vodoměr',
		'consumption', '2024-05-31 00:00:00+00', 4, true, '50005678', 'OP-102', 'VOD-55', 'GID100'),
	('prague-7', '44444444-4444-4444-4444-444444444444', 1, '22222222-2222-2222-2222-222222222222', 'sub',
		'heat_meter', 'Podružné měření tělocvična', 'tělocvična', NULL, NULL, true, NULL, NULL, 'TEP-78', NULL),
	('prague-7', '55555555-5555-5555-5555-555555555555', 2, NULL, 'main', 'electricity_meter', 'Elektroměr vrátnice',
		'consumption', NULL, NULL, true, '859182400000000099', 'OP-200', 'EL-999', 'GIDPOR1');

INSERT INTO enapo_porsenna_consumption (source, device_id, "var", "period", value, unit, commodity, "count") VALUES
	('prague-7', '11111111-1111-1111-1111-111111111111', 'yearly', '2025', 12.4, 'MWH', 'electricity_meter', 365),
	('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2023', 512.3, 'GJ', 'heat_meter', 365),
	('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2024', 498.1, 'GJ', 'heat_meter', 366),
	('prague-7', '33333333-3333-3333-3333-333333333333', 'yearly', '2023', 210, 'M3', 'water_meter', 365),
	('prague-7', '55555555-5555-5555-5555-555555555555', 'yearly', '2024', 5.5, 'MWH', 'electricity_meter', 366);
