<?php

namespace App\Models;

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

class Subscription extends Model
{
    use HasFactory;

    public function plates(){
        return $this->hasMany(Plate::class);
    }

    public function plan(){
        return $this->belongsTo(Plan::class);
    }

    public function user(){
        return $this->belongsTo(User::class);
    }


    public function customPlan(){
        return $this->belongsTo(CustomPlan::class);
    }


    public function balance(){
        $bal = $this->amount;
        $plates = $this->plates->where('status', 'delivered')->sum('amount');
        $bal -= $plates;
        return $bal;
    }
}
