<?php

namespace App\Models;

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

class Barang extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'pakets';
    
    protected $fillable = [
        'nama_paket',
        'slug',
        'jenis_paket',
        'harga',
        'image',
        'keterangan',
        'detail_barang',
        'stok',
        'status',
        'rating',
        'total_rating',
        'minimum_order',
        'maximum_order'
    ];

    protected $casts = [
        'detail_barang' => 'array',
        'harga' => 'decimal:2',
        'rating' => 'decimal:2'
    ];

    protected $dates = ['deleted_at'];

    protected $attributes = [
        'status' => 'aktif',
        'rating' => 0.00,
        'total_rating' => 0,
        'minimum_order' => 1,
        'maximum_order' => null
    ];

    // Accessor untuk mendapatkan URL gambar
    public function getImageUrlAttribute()
    {
        return $this->image ? asset('storage/' . $this->image) : null;
    }

    // Accessor untuk mendapatkan nama yang akan ditampilkan
    public function getNamaBarangAttribute()
    {
        return $this->nama_paket;
    }

    // Accessor untuk mendapatkan kategori yang akan ditampilkan
    public function getKategoriAttribute()
    {
        return $this->jenis_paket;
    }
} 