<?php

namespace Modules\Payment\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\ChipOrder\Models\ChipOrder;
use Modules\Subscription\Models\Subscription;
use Modules\User\Models\User;

class Payment extends Model
{
    //use soft delete
    use SoftDeletes;

    protected $fillable = [
        'status',
        'user_id',
        'subscription_id',
        'chip_order_id',
        'ref',
    ];

    public function user()
    {
        return $this->belongsTo(User::class)->withTrashed();
    }
    public function subscription()
    {
        return $this->belongsTo(Subscription::class)->withTrashed();
    }
    public function order()
    {
        return $this->belongsTo(ChipOrder::class)->withTrashed();
    }
    public function details()
    {
        return $this->hasMany(PaymentDetails::class);
    }
    public function meta()
    {
        return $this->details()->where('type', 'create')->whereNotNull('meta')->first();
    }
}
