<?php

namespace App\Models;

use App\Constants\Status;

use App\Traits\Searchable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Payment extends Model
{
    use HasFactory;
    use Searchable;

    protected $guarded  = ['id'];

    protected $casts = [
        'expired_at' => 'datetime'
    ];

    protected  $table = 'uplink_payments';

    public function payerUser()
    {
        return $this->belongsTo(User::class, 'payer_user_id');
    }

    public function receiverUser()
    {
        return $this->belongsTo(User::class, 'receiver_user_id');
    }


    public function statusBadge(): Attribute
    {
        return new Attribute(
            get: fn() => $this->badgeData(),
        );
    }

    public function badgeData()
    {
        $html = '';
        switch ($this->status) {
            case Status::Pending:
                $html = '<span class="badge badge--warning">' . trans('Pending') . '</span>';
                break;
            case Status::Approved:
                $html = '<span class="badge badge--success">' . trans('Approved') . '</span>';
                break;
            case Status::Rejected:
                $html = '<span class="badge badge--danger text-white">' . trans('Rejected') . '</span>';
                break;
        }
        return $html;
    }
}
