<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('publications', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('department_id');
            $table->string('first_author_name');
            $table->text('co_authors')->nullable(); // For storing multiple co-author names
            $table->dateTime('start_date');
            $table->dateTime('end_date');
            $table->integer('num_days');
            $table->string('activity_type');
            $table->string('title');
            $table->text('affiliation'); // Name of conference/journal
            $table->string('organizing_institute');
            $table->text('venue_address');
            $table->enum('is_peer_reviewed', ['yes', 'no'])->default('no');
            $table->text('scopus_link')->nullable(); // Null means not Scopus indexed
            $table->text('sci_link')->nullable(); // Null means not SCI indexed
            $table->string('paper_file')->nullable(); // For file path
            $table->unsignedBigInteger('faculty_id'); // Faculty who uploaded the publication
            
            // Foreign keys
            $table->foreign('department_id')->references('id')->on('departments')->onDelete('cascade');
            $table->foreign('faculty_id')->references('id')->on('users')->onDelete('cascade');
            
            // Indexes for better performance
            $table->index('department_id');
            $table->index('faculty_id');
            $table->index(['start_date', 'end_date']);
            
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('publications');
    }
};