<?php

namespace App\Models;

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

class Payment extends Model
{
    use HasFactory;

    public const STATUS_UNPAID = 'unpaid';
    public const STATUS_UPLOADED = 'uploaded';
    public const STATUS_VERIFIED = 'verified';
    public const STATUS_REJECTED = 'rejected';

    protected $fillable = [
        'booking_id',
        'payment_method',
        'amount',
        'proof_payment',
        'paid_at',
        'verified_by',
        'verified_at',
        'payment_status',
        'rejection_note',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
        'paid_at' => 'datetime',
        'verified_at' => 'datetime',
    ];

    public function getStatusLabelAttribute(): string
    {
        return match ($this->payment_status) {
            self::STATUS_UPLOADED => 'Menunggu Verifikasi',
            self::STATUS_VERIFIED => 'Diverifikasi',
            self::STATUS_REJECTED => 'Ditolak',
            default => 'Belum Bayar',
        };
    }

    public function booking(): BelongsTo
    {
        return $this->belongsTo(Booking::class);
    }

    public function verifiedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'verified_by');
    }
}
