<?php

namespace App\Models;

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

class Exhibit extends Model
{
    use HasFactory;

    protected $fillable = [
        'gallery_id',
        'exhibit_name',
        'exhibit_icon_path',
        'short_description',
        'language',
        'auto_play',
        'order',
        'video_path',
        'show_description_flag',
        'next_exhibit_ids',
        'close_after_autoplay',  // New field
        'show_in_app_icon',      // New field
        'next_exhibit_id',       // New single selection field
        'previous_exhibit_id',   // New field
    ];

    public function gallery()
    {
        return $this->belongsTo(Gallery::class);
    }

    public function getNextExhibitIdsAttribute($value)
    {
        return explode(',', $value);
    }

    public function setNextExhibitIdsAttribute($value)
    {
        $this->attributes['next_exhibit_ids'] = implode(',', $value);
    }

    public function nextExhibit()
    {
        return $this->belongsTo(Exhibit::class, 'next_exhibit_id');
    }

    public function previousExhibit()
    {
        return $this->belongsTo(Exhibit::class, 'previous_exhibit_id');
    }
}
