<?php

namespace Database\Seeders;

use App\Models\Publication;
use Carbon\Carbon;
use Illuminate\Database\Seeder;

class PublicationSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Sample data for publications
        $firstAuthorNames = [
            'Dr. Sarah Johnson', 'Prof. Michael Chen', 'Dr. Emily Rodriguez', 
            'Dr. David Kim', 'Prof. Amina Patel', 'Dr. Thomas Wilson',
            'Prof. Lisa Wang', 'Dr. Robert Garcia', 'Prof. Olivia Smith',
            'Dr. James Lee', 'Prof. Sophia Martinez', 'Dr. Alexander Brown'
        ];
        
        $coAuthors = [
            'Dr. John Smith, Dr. Maria Garcia, Prof. Wei Zhang',
            'Prof. Aya Nakamura, Dr. Carlos Mendez',
            'Dr. Rebecca Johnson, Prof. Andrew Davis, Dr. Fatima Khan',
            'Prof. Samuel Taylor, Dr. Hannah Kim',
            'Dr. Jason Miller, Prof. Diana Lewis',
            'Prof. Kevin Park, Dr. Natalie Chen, Dr. Omar Hassan',
            null, // Some publications might not have co-authors
        ];
        
        $activityTypes = [
            'Journal Article', 'Conference Paper', 'Book Chapter', 
            'Research Paper', 'Technical Report', 'Review Article'
        ];
        
        $titles = [
            'Advances in Machine Learning for Healthcare Applications',
            'Sustainable Energy Systems: A Comprehensive Review',
            'Novel Approaches to Quantum Computing',
            'The Impact of Climate Change on Marine Ecosystems',
            'Artificial Intelligence in Educational Technology',
            'Cybersecurity Challenges in IoT Environments',
            'Emerging Materials for Next-Generation Batteries',
            'Blockchain Applications in Supply Chain Management',
            'Genetic Factors in Autoimmune Disorders',
            'Urban Planning Strategies for Smart Cities',
            'Deep Learning Methods for Natural Language Processing',
            'Renewable Energy Integration in Power Grids',
            'Ethical Considerations in Biotechnology Research',
            'Innovative Techniques in Software Engineering',
            'Nanoparticles for Targeted Drug Delivery'
        ];
        
        $affiliations = [
            'International Journal of Computer Science',
            'IEEE Transactions on Artificial Intelligence',
            'Nature Communications',
            'ACM Computing Surveys',
            'Journal of Applied Physics',
            'Renewable Energy',
            'International Conference on Machine Learning',
            'IEEE Conference on Computer Vision and Pattern Recognition',
            'Annual Conference on Neural Information Processing Systems',
            'International Conference on Software Engineering',
            'Springer Handbook of Advanced Materials',
            'Journal of Educational Technology',
            'Environmental Science & Technology',
            'Conference on Human Factors in Computing Systems',
            'Journal of Biomedical Materials Research'
        ];
        
        $organizingInstitutes = [
            'IEEE', 'ACM', 'Elsevier', 'Springer', 'Nature Publishing Group',
            'MIT Press', 'Cambridge University Press', 'Oxford University Press',
            'National Science Foundation', 'American Chemical Society',
            'Royal Society of Chemistry', 'Institute of Physics',
            'Association for Computing Machinery', 'Taylor & Francis Group'
        ];
        
        $venueAddresses = [
            'Harvard University, Cambridge, MA, USA',
            'Technical University of Munich, Germany',
            'National University of Singapore, Singapore',
            'University of Tokyo, Japan',
            'ETH Zurich, Switzerland',
            'University of California, Berkeley, USA',
            'Imperial College London, UK',
            'Tsinghua University, Beijing, China',
            'University of Toronto, Canada',
            'Technical University of Denmark, Copenhagen, Denmark',
            'Seoul National University, South Korea',
            'University of Melbourne, Australia'
        ];
        
        $isPeerReviewed = ['yes', 'no'];
        
        // Create 50 sample publication records
        for ($i = 0; $i < 10; $i++) {
            // Generate random dates
            $startDate = now()->subDays(rand(30, 365))->addHours(rand(0, 23))->addMinutes(rand(0, 59));
            $endDate = (clone $startDate)->addDays(rand(1, 5))->addHours(rand(0, 23))->addMinutes(rand(0, 59));
            $numDays = $startDate->diffInDays($endDate) ?: 1;
            
            // Determine if the publication is indexed
            $isPeer = $isPeerReviewed[array_rand($isPeerReviewed)];
            $scopusLink = $isPeer === 'yes' && rand(0, 1) ? 'https://www.scopus.com/record/display.uri?eid=2-s2.0-' . rand(10000000000, 99999999999) : null;
            $sciLink = $isPeer === 'yes' && rand(0, 1) ? 'https://www.webofscience.com/wos/woscc/full-record/' . rand(100000, 999999) : null;
            
            // Create the publication record
            Publication::create([
                'department_id' => rand(1, 5),
                'first_author_name' => $firstAuthorNames[array_rand($firstAuthorNames)],
                'co_authors' => $coAuthors[array_rand($coAuthors)],
                'start_date' => $startDate->format('Y-m-d H:i:s'),
                'end_date' => $endDate->format('Y-m-d H:i:s'),
                'num_days' => $numDays,
                'activity_type' => $activityTypes[array_rand($activityTypes)],
                'title' => $titles[array_rand($titles)],
                'affiliation' => $affiliations[array_rand($affiliations)],
                'organizing_institute' => $organizingInstitutes[array_rand($organizingInstitutes)],
                'venue_address' => $venueAddresses[array_rand($venueAddresses)],
                'is_peer_reviewed' => $isPeer,
                'scopus_link' => $scopusLink,
                'sci_link' => $sciLink,
                'paper_file' => null, // Null for paper file
                'faculty_id' => rand(1, 5),
            ]);
        }
    }
}