<?php

namespace App\Models;

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

class UserSubscriber extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'subscribe_plan_id',
        'expired_at',
        'subscription_id',
        'purchase_token',
        'is_free'
    ];

    public function subscribe()
    {
        return $this->belongsTo(SubscribePlan::class,'subscribe_plan_id');
    }

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

    public function getExpiredDayAttribute()
    {
        return $this->expired_at->diffInDays(now());
    }

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