-- Core seed data

DELETE FROM login_attempts;
DELETE FROM password_resets;
DELETE FROM email_verifications;
DELETE FROM user_invitations;
DELETE FROM audit_logs;
DELETE FROM cloudflare_accounts;
DELETE FROM sites;
DELETE FROM user_roles;
DELETE FROM users;
DELETE FROM role_permissions;
DELETE FROM permissions;
DELETE FROM roles;

INSERT INTO roles (id, slug, label, is_system) VALUES
(1,'super_admin','Super Administrador',1),
(2,'admin','Administrador',1),
(3,'colaborador','Colaborador',1);

INSERT INTO permissions (`key`, label, module_slug) VALUES
('core:users:view','Ver usuários',NULL),
('core:users:create','Criar usuários',NULL),
('core:users:edit','Editar usuários',NULL),
('core:users:delete','Excluir usuários',NULL),
('core:roles:view','Ver papéis',NULL),
('core:roles:edit','Editar papéis',NULL),
('core:modules:view','Ver módulos',NULL),
('core:modules:manage','Gerenciar módulos',NULL),
('core:settings:view','Ver configurações',NULL),
('core:settings:edit','Editar configurações',NULL),
('core:logs:view','Ver logs',NULL),
('core:logs:delete','Excluir logs',NULL),
('core:backups:view','Ver backups',NULL),
('core:backups:download','Baixar backups',NULL);

INSERT INTO role_permissions (role_id, permission_id)
SELECT 1, p.id FROM permissions p;

INSERT INTO role_permissions (role_id, permission_id)
SELECT 2, p.id FROM permissions p WHERE p.`key` NOT LIKE '%:delete';

INSERT INTO role_permissions (role_id, permission_id)
SELECT 3, p.id FROM permissions p WHERE p.`key` LIKE '%:view';

INSERT INTO users (id, name, email, password_hash, email_verified_at, status, created_at, updated_at) VALUES
(1, 'Super Administrador', 'admin@tools.test', '$2y$12$PJ1exbG7zx.zK8n5P2g3PupsLIMuTS/ih9.Erb/72wLocqRNlLUPa', NOW(), 'active', NOW(), NOW());

INSERT INTO user_roles (user_id, role_id) VALUES (1, 1);
