<?php

namespace App\Models;

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

class TransaksiBuket extends Model
{
    use HasFactory;

    protected $table = 'transaksi_bukets';
    protected $primaryKey = 'id_transaksi';

    protected $fillable = [
        'no_invoice',
        'id_pelanggan',
        'id_buket',
        'request',
        'ucapan',
        'tgl_ambil',
        'total_bayar',
        'bukti_bayar',
        'status_transaksi',
    ];

    // Relasi Balik
    public function pelanggan()
    {
        return $this->belongsTo(Pelanggan::class, 'id_pelanggan');
    }

    public function buket()
    {
        return $this->belongsTo(Buket::class, 'id_buket');
    }
    // Di Model TransaksiBuket.php

    public function getStatusLabelAttribute()
    {
        // Mapping status ke class subtle dan teks
        $statusMap = [
            'menunggu_verifikasi' => [
                'class' => 'bg-info-subtle', // text-emphasis agar kontras
                'text'  => 'Menunggu Verifikasi'
            ],
            'diterima' => [
                'class' => 'bg-warning-subtle ',
                'text'  => 'Diterima'
            ],
            'selesai' => [
                'class' => 'bg-success-subtle',
                'text'  => 'Selesai'
            ],
            'dibatalkan' => [
                'class' => 'bg-info-subtle ',
                'text'  => 'Dibatalkan'
            ],
            'ditolak' => [
                'class' => 'bg-danger-subtle',
                'text'  => 'Ditolak'
            ],
        ];

        // Mengambil data berdasarkan status_transaksi, default ke secondary jika tidak ada
        return (object) ($statusMap[$this->status_transaksi] ?? [
            'class' => 'bg-secondary-subtle text-secondary',
            'text'  => 'Unknown'
        ]);
    }
}
