<?php

namespace Database\Seeders;

use App\Models\ImportedJob;
use App\Models\JobSource;
use Illuminate\Database\Seeder;

class ImportedJobSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $source = JobSource::query()->where('slug', 'manual-curation')->firstOrFail();

        $jobs = [
            [
                'external_id' => 'manual-product-ops-001',
                'title' => 'Remote Product Operations Associate',
                'company' => 'Northstar Labs',
                'category' => 'operations',
                'employment_type' => 'full_time',
                'experience_level' => 'mid',
                'summary' => 'Coordinate launches, document workflows, and support distributed product teams.',
                'skills' => ['operations', 'documentation', 'project management', 'remote communication'],
                'tags' => ['async', 'product', 'global'],
            ],
            [
                'external_id' => 'manual-support-001',
                'title' => 'Customer Support Specialist',
                'company' => 'CalmDesk',
                'category' => 'support',
                'employment_type' => 'contract',
                'experience_level' => 'junior',
                'summary' => 'Help SaaS customers through chat and email while improving support macros.',
                'skills' => ['customer support', 'saas', 'email support', 'communication'],
                'tags' => ['support', 'chat', 'email'],
            ],
            [
                'external_id' => 'manual-writing-001',
                'title' => 'Remote Content Writer',
                'company' => 'BrightPath Media',
                'category' => 'writing',
                'employment_type' => 'freelance',
                'experience_level' => 'mid',
                'summary' => 'Write search-focused articles, landing pages, and newsletter content for B2B clients.',
                'skills' => ['content writing', 'seo', 'research', 'editing'],
                'tags' => ['writing', 'seo', 'b2b'],
            ],
            [
                'external_id' => 'manual-tech-001',
                'title' => 'Laravel Full-Stack Developer',
                'company' => 'CloudForge Studio',
                'category' => 'tech',
                'employment_type' => 'full_time',
                'experience_level' => 'senior',
                'summary' => 'Build Laravel, Blade, and Tailwind features for a distributed product team.',
                'skills' => ['laravel', 'php', 'tailwind css', 'mysql', 'javascript'],
                'tags' => ['laravel', 'backend', 'frontend'],
            ],
            [
                'external_id' => 'manual-va-001',
                'title' => 'Virtual Assistant for Founder Operations',
                'company' => 'LaunchRoom',
                'category' => 'virtual-assistant',
                'employment_type' => 'part_time',
                'experience_level' => 'entry',
                'summary' => 'Manage inboxes, scheduling, research tasks, and lightweight operations for a remote founder.',
                'skills' => ['virtual assistant', 'calendar management', 'research', 'email'],
                'tags' => ['assistant', 'operations', 'part-time'],
            ],
        ];

        foreach ($jobs as $job) {
            ImportedJob::query()->updateOrCreate(
                [
                    'job_source_id' => $source->id,
                    'external_id' => $job['external_id'],
                ],
                [
                    ...$job,
                    'job_source_id' => $source->id,
                    'location_type' => 'remote',
                    'country_code' => null,
                    'timezone' => null,
                    'salary_currency' => 'USD',
                    'salary_min' => null,
                    'salary_max' => null,
                    'description' => $job['summary'],
                    'source_url' => config('app.url').'/sample-jobs/'.$job['external_id'],
                    'apply_url' => config('app.url').'/sample-apply/'.$job['external_id'],
                    'source_attribution' => 'Sample job seeded for local development.',
                    'status' => ImportedJob::STATUS_ACTIVE,
                    'is_featured' => false,
                    'posted_at' => now()->subDays(rand(1, 12)),
                    'expires_at' => now()->addDays(30),
                    'last_seen_at' => now(),
                    'raw_payload' => $job,
                ]
            );
        }
    }
}
