<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class Gallery extends Model
{
    protected $fillable = ['kategori', 'judul', 'foto'];

    public function getFotoUrlAttribute(): ?string
    {
        if (!$this->foto) return null;
        if (str_starts_with($this->foto, 'http')) return $this->foto;
        return Storage::url($this->foto);
    }

    public function getKategoriLabelAttribute(): string
    {
        return match($this->kategori) {
            'kegiatan_desa'   => 'Kegiatan Desa',
            'masyarakat'      => 'Masyarakat',
            'alam_lingkungan' => 'Alam & Lingkungan',
            'potensi_desa'    => 'Potensi Desa',
            'pemerintahan'    => 'Pemerintahan',
            'wisata'          => 'Wisata',
            default           => ucfirst($this->kategori),
        };
    }
}
