<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Publication extends Model
{
    use HasFactory;

    protected $fillable = [
        'department_id',
        'first_author_name',
        'co_authors',
        'start_date',
        'end_date',
        'num_days',
        'activity_type',
        'title',
        'affiliation',
        'organizing_institute',
        'venue_address',
        'is_peer_reviewed',
        'scopus_link',
        'sci_link',
        'paper_file',
        'faculty_id'
    ];

    protected $casts = [
        'start_date' => 'datetime',
        'end_date' => 'datetime',
        'num_days' => 'integer',
        'is_peer_reviewed' => 'string'
    ];

    /**
     * Get the department that owns the publication.
     */
    public function department()
    {
        return $this->belongsTo(Department::class);
    }

    /**
     * Get the faculty user that owns the publication.
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'faculty_id');
    }

    /**
     * Check if the publication is Scopus indexed.
     */
    public function isScopusIndexed()
    {
        return !is_null($this->scopus_link);
    }

    /**
     * Check if the publication is SCI indexed.
     */
    public function isSciIndexed()
    {
        return !is_null($this->sci_link);
    }
}