/**
 * Tags Seeder
 * Seeds job_tags table with categories: area, level, stack
 */
import { pool } from '../db.js';

const seedTags = async () => {
    console.log('🏷️  Seeding job tags...');

    const tags = [
        // Area (Departamento/Área)
        { name: 'Engineering', category: 'area' },
        { name: 'Design', category: 'area' },
        { name: 'Product', category: 'area' },
        { name: 'Marketing', category: 'area' },
        { name: 'Sales', category: 'area' },
        { name: 'Customer Success', category: 'area' },
        { name: 'Human Resources', category: 'area' },
        { name: 'Finance', category: 'area' },
        { name: 'Operations', category: 'area' },
        { name: 'Data', category: 'area' },
        { name: 'Quality Assurance', category: 'area' },
        { name: 'DevOps', category: 'area' },
        { name: 'Security', category: 'area' },
        { name: 'Legal', category: 'area' },
        { name: 'Administrative', category: 'area' },

        // Level (Nível)
        { name: 'Intern', category: 'level' },
        { name: 'Junior', category: 'level' },
        { name: 'Mid-Level', category: 'level' },
        { name: 'Senior', category: 'level' },
        { name: 'Lead', category: 'level' },
        { name: 'Staff', category: 'level' },
        { name: 'Principal', category: 'level' },
        { name: 'Manager', category: 'level' },
        { name: 'Director', category: 'level' },
        { name: 'VP', category: 'level' },
        { name: 'C-Level', category: 'level' },

        // Stack (Tecnologias)
        { name: 'JavaScript', category: 'stack' },
        { name: 'TypeScript', category: 'stack' },
        { name: 'Python', category: 'stack' },
        { name: 'Go', category: 'stack' },
        { name: 'Java', category: 'stack' },
        { name: 'C#', category: 'stack' },
        { name: 'Ruby', category: 'stack' },
        { name: 'PHP', category: 'stack' },
        { name: 'Rust', category: 'stack' },
        { name: 'Swift', category: 'stack' },
        { name: 'Kotlin', category: 'stack' },
        { name: 'React', category: 'stack' },
        { name: 'Vue.js', category: 'stack' },
        { name: 'Angular', category: 'stack' },
        { name: 'Next.js', category: 'stack' },
        { name: 'Node.js', category: 'stack' },
        { name: 'NestJS', category: 'stack' },
        { name: 'Django', category: 'stack' },
        { name: 'FastAPI', category: 'stack' },
        { name: 'Spring Boot', category: 'stack' },
        { name: '.NET', category: 'stack' },
        { name: 'Ruby on Rails', category: 'stack' },
        { name: 'Laravel', category: 'stack' },
        { name: 'PostgreSQL', category: 'stack' },
        { name: 'MySQL', category: 'stack' },
        { name: 'MongoDB', category: 'stack' },
        { name: 'Redis', category: 'stack' },
        { name: 'Elasticsearch', category: 'stack' },
        { name: 'Docker', category: 'stack' },
        { name: 'Kubernetes', category: 'stack' },
        { name: 'AWS', category: 'stack' },
        { name: 'GCP', category: 'stack' },
        { name: 'Azure', category: 'stack' },
        { name: 'Terraform', category: 'stack' },
        { name: 'GraphQL', category: 'stack' },
        { name: 'REST API', category: 'stack' },
        { name: 'Figma', category: 'stack' },
        { name: 'Tailwind CSS', category: 'stack' },
        { name: 'Git', category: 'stack' },
        { name: 'CI/CD', category: 'stack' },
        { name: 'Agile/Scrum', category: 'stack' },
    ];

    let inserted = 0;
    let skipped = 0;

    for (const tag of tags) {
        try {
            // Check if tag already exists
            const exists = await pool.query(
                'SELECT id FROM job_tags WHERE name = $1 AND category = $2',
                [tag.name, tag.category]
            );

            if (exists.rows.length > 0) {
                skipped++;
                continue;
            }

            await pool.query(
                `INSERT INTO job_tags (name, category, active, created_at, updated_at)
                 VALUES ($1, $2, true, NOW(), NOW())`,
                [tag.name, tag.category]
            );
            inserted++;
        } catch (error) {
            console.error(`  ❌ Error inserting tag ${tag.name}:`, error.message);
        }
    }

    console.log(`  ✅ Tags: ${inserted} inserted, ${skipped} skipped (already exist)`);
    return { inserted, skipped };
};

export { seedTags };
