-- Create groups
INSERT INTO groups (id, account_id, name, issued, resources, integration_ref_id, integration_ref_integration_type) VALUES ('da915d4f72fa42f68509', 'd898edfkclh0009hc94g', 'DD', 'api', '', NULL, NULL);
INSERT INTO groups (id, account_id, name, issued, resources, integration_ref_id, integration_ref_integration_type) VALUES ('adba740446b0413b89ab', 'd898edfkclh0009hc94g', 'KPT', 'api', '', NULL, NULL);
INSERT INTO groups (id, account_id, name, issued, resources, integration_ref_id, integration_ref_integration_type) VALUES ('cc9168e7b8d7437499c2', 'd898edfkclh0009hc94g', 'Personal', 'api', '', NULL, NULL);

-- Disable Default policy (cross-group would break isolation)
UPDATE policies SET enabled = 0 WHERE name = 'Default';

-- Create policies
INSERT INTO policies (id, account_id, name, description, enabled, source_posture_checks) VALUES ('6d19a58b5f144f27ade5', 'd898edfkclh0009hc94g', 'DD-Policy', 'Erlaubt Traffic zwischen allen DD-Geräten', 1, '');
INSERT INTO policies (id, account_id, name, description, enabled, source_posture_checks) VALUES ('6915c5d4b7d94b959e9f', 'd898edfkclh0009hc94g', 'KPT-Policy', 'Erlaubt Traffic zwischen allen KPT-Geräten', 1, '');
INSERT INTO policies (id, account_id, name, description, enabled, source_posture_checks) VALUES ('5bbf4b1be1ec479ca92a', 'd898edfkclh0009hc94g', 'Personal-Policy', 'Erlaubt Traffic zwischen allen Personal-Geräten', 1, '');

-- Create policy rules (bidirectional = group talks to itself)
INSERT INTO policy_rules (id, policy_id, name, description, enabled, action, destinations, destination_resource, sources, source_resource, bidirectional, protocol, ports, port_ranges, authorized_groups, authorized_user)
VALUES ('89ade5fb63bf4669a160', '6d19a58b5f144f27ade5', 'DD-Rule', 'DD intern', 1, 'accept', '["da915d4f72fa42f68509"]', '{"ID":"","Type":""}', '["da915d4f72fa42f68509"]', '{"ID":"","Type":""}', 1, 'all', '', '', '', '');

INSERT INTO policy_rules (id, policy_id, name, description, enabled, action, destinations, destination_resource, sources, source_resource, bidirectional, protocol, ports, port_ranges, authorized_groups, authorized_user)
VALUES ('92956ad519a94347ae15', '6915c5d4b7d94b959e9f', 'KPT-Rule', 'KPT intern', 1, 'accept', '["adba740446b0413b89ab"]', '{"ID":"","Type":""}', '["adba740446b0413b89ab"]', '{"ID":"","Type":""}', 1, 'all', '', '', '', '');

INSERT INTO policy_rules (id, policy_id, name, description, enabled, action, destinations, destination_resource, sources, source_resource, bidirectional, protocol, ports, port_ranges, authorized_groups, authorized_user)
VALUES ('1251d4c9fb824904a715', '5bbf4b1be1ec479ca92a', 'Personal-Rule', 'Personal intern', 1, 'accept', '["cc9168e7b8d7437499c2"]', '{"ID":"","Type":""}', '["cc9168e7b8d7437499c2"]', '{"ID":"","Type":""}', 1, 'all', '', '', '', '');

-- Add CT 111 (Netbird-Server) to all groups so jeder Gruppe ihn erreichen kann
INSERT INTO group_peers (account_id, group_id, peer_id) VALUES ('d898edfkclh0009hc94g', 'da915d4f72fa42f68509', 'd898qfnkclh0008igda0');
INSERT INTO group_peers (account_id, group_id, peer_id) VALUES ('d898edfkclh0009hc94g', 'adba740446b0413b89ab', 'd898qfnkclh0008igda0');
INSERT INTO group_peers (account_id, group_id, peer_id) VALUES ('d898edfkclh0009hc94g', 'cc9168e7b8d7437499c2', 'd898qfnkclh0008igda0');
