-- Total: 69 Skills
-- Migration 023: Vollständiger Skills-Import
-- Purpose: Produktionsreifer Import aller 69 Skills mit vollständiger Kategorisierung
-- Source: Fähigkeitsmatrix https://karatetrainer.net/index.php?title=Fähigkeitsmatrix
-- Date: 2026-04-27

-- ======================================================================
-- CLEANUP: Alte Daten löschen
-- ======================================================================

-- Erst M:N-Beziehungen löschen
DELETE FROM exercise_skills;

-- Skills löschen (Cascades zu skill_level_definitions)
DELETE FROM skills;

-- Kategorien löschen
DELETE FROM skill_categories;
DELETE FROM skill_main_categories WHERE id > 0;  -- Falls Tabelle existiert

-- ======================================================================
-- 1. HAUPT-KATEGORIEN
-- ======================================================================

INSERT INTO skill_main_categories (name, slug, description, sort_order) VALUES
('KARATE Fähigkeiten', 'karate', 'Karate-spezifische Techniken und Fähigkeiten', 1),
('ALLGEMEINE sportliche Fähigkeiten', 'allgemeine', 'Universelle sportliche und mentale Fähigkeiten', 2);

-- ======================================================================
-- 2. UNTERKATEGORIEN
-- ======================================================================

INSERT INTO skill_categories (name, slug, main_category_id, description, sort_order) VALUES
('Kata', 'kata', (SELECT id FROM skill_main_categories WHERE slug='karate'), '', 1),
('Kihon', 'kihon', (SELECT id FROM skill_main_categories WHERE slug='karate'), '', 2),
('Kumite', 'kumite', (SELECT id FROM skill_main_categories WHERE slug='karate'), '', 3),
('Selbstverteidigung', 'selbstverteidigung', (SELECT id FROM skill_main_categories WHERE slug='karate'), '', 4),
('Kognition', 'kognition', (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '', 5),
('Kondition', 'kondition', (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '', 6),
('Koordination', 'koordination', (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '', 7),
('Psychische Fähigkeiten', 'psychische_faehigkeiten', (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '', 8),
('Soziale Fähigkeiten', 'soziale_faehigkeiten', (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '', 9);

-- ======================================================================
-- 3. SKILLS
-- ======================================================================

INSERT INTO skills (name, description, category_id, main_category_id, focus_areas) VALUES
('Technik Kombination', '', (SELECT id FROM skill_categories WHERE slug='kata'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Kata Ablauf', '', (SELECT id FROM skill_categories WHERE slug='kata'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Bunkai', '', (SELECT id FROM skill_categories WHERE slug='kata'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Oyo', '', (SELECT id FROM skill_categories WHERE slug='kata'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Henka', '', (SELECT id FROM skill_categories WHERE slug='kata'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Kakushi', '', (SELECT id FROM skill_categories WHERE slug='kata'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Kata Atmung', '', (SELECT id FROM skill_categories WHERE slug='kata'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Kata Rhythmus', '', (SELECT id FROM skill_categories WHERE slug='kata'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Dachi Waza', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Uke Waza', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Zuki Waza', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Uchi Waza', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Geri Waza', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Nage Waza', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Nukite Waza', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Ken Waza', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Hüfteinsatz', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Kime', '', (SELECT id FROM skill_categories WHERE slug='kihon'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Beinarbeit', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Distanzkontrolle', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Angriff', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Abwehr Konter', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Präzision', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Antizipation', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Timing', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Taktik', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Fokus', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Mentale Stärke', '', (SELECT id FROM skill_categories WHERE slug='kumite'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Gefahrenbewustsein', '', (SELECT id FROM skill_categories WHERE slug='selbstverteidigung'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Selbstbehauptung', '', (SELECT id FROM skill_categories WHERE slug='selbstverteidigung'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Selbstschutz', '', (SELECT id FROM skill_categories WHERE slug='selbstverteidigung'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Gefahrenabwehr', '', (SELECT id FROM skill_categories WHERE slug='selbstverteidigung'), (SELECT id FROM skill_main_categories WHERE slug='karate'), '["karate"]'::jsonb),
('Aufmerksamkeit', '', (SELECT id FROM skill_categories WHERE slug='kognition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Wahrnehmung', '', (SELECT id FROM skill_categories WHERE slug='kognition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Urteilsvermögen', '', (SELECT id FROM skill_categories WHERE slug='kognition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Merkfähigkeit', '', (SELECT id FROM skill_categories WHERE slug='kognition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Lernfähigkeit', '', (SELECT id FROM skill_categories WHERE slug='kognition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Maximalkraft', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Schnellkraft', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Reaktivkraft', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Kraftausdauer', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Muskelaufbau', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Reaktionsschnelligkeit', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Bewegungsschnelligkeit', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Handlungsschnelligkeit', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Schnelligkeitsausdauer', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Grundlagenausdauer', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Aerobe Ausdauer', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Anaerobe Ausdauer', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Regenerationsfähigkeit', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Ermüdungswiderstandsfähigkeit', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Flexibilität', '', (SELECT id FROM skill_categories WHERE slug='kondition'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Orientierung', '', (SELECT id FROM skill_categories WHERE slug='koordination'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Differenzierung', '', (SELECT id FROM skill_categories WHERE slug='koordination'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Kopplung', '', (SELECT id FROM skill_categories WHERE slug='koordination'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Gleichgewicht', '', (SELECT id FROM skill_categories WHERE slug='koordination'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Rhythmisierung', '', (SELECT id FROM skill_categories WHERE slug='koordination'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Reaktion', '', (SELECT id FROM skill_categories WHERE slug='koordination'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Umstellung', '', (SELECT id FROM skill_categories WHERE slug='koordination'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Selbstvertrauen', '', (SELECT id FROM skill_categories WHERE slug='psychische_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Konzentration', '', (SELECT id FROM skill_categories WHERE slug='psychische_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Emotionale Kontrolle', '', (SELECT id FROM skill_categories WHERE slug='psychische_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Motivation', '', (SELECT id FROM skill_categories WHERE slug='psychische_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Stressresistenz', '', (SELECT id FROM skill_categories WHERE slug='psychische_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Stressregulation', '', (SELECT id FROM skill_categories WHERE slug='psychische_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Deeskalation', '', (SELECT id FROM skill_categories WHERE slug='soziale_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Selbstdisziplin', '', (SELECT id FROM skill_categories WHERE slug='soziale_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Toleranz', '', (SELECT id FROM skill_categories WHERE slug='soziale_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb),
('Fairness', '', (SELECT id FROM skill_categories WHERE slug='soziale_faehigkeiten'), (SELECT id FROM skill_main_categories WHERE slug='allgemeine'), '["universal"]'::jsonb);

-- ======================================================================
-- 4. VERIFIKATION
-- ======================================================================

-- Sollte 69 Skills ergeben
DO $$
DECLARE
    skill_count INT;
BEGIN
    SELECT COUNT(*) INTO skill_count FROM skills;

    IF skill_count != 69 THEN
        RAISE WARNING 'FEHLER: % Skills gefunden, erwartet 69', skill_count;
    ELSE
        RAISE NOTICE 'OK: 69 Skills importiert';
    END IF;
END $$;

-- Zeige Verteilung
SELECT
    mc.name AS hauptkategorie,
    sc.name AS unterkategorie,
    COUNT(s.id) AS anzahl_skills
FROM skills s
JOIN skill_categories sc ON s.category_id = sc.id
JOIN skill_main_categories mc ON s.main_category_id = mc.id
GROUP BY mc.name, sc.name, mc.sort_order, sc.sort_order
ORDER BY mc.sort_order, sc.sort_order;

