<?php

namespace Modules\VetClinic\Entities;

use Illuminate\Database\Eloquent\Model;

class VcMedicineBatch extends Model
{
    protected $table = 'vc_medicine_batches';
    protected $guarded = ['id'];

    protected $casts = [
        'manufactured_date' => 'date',
        'expiry_date'       => 'date',
    ];

    public function medicine()
    {
        return $this->belongsTo(VcMedicine::class, 'medicine_id');
    }

    public function getIsExpiredAttribute()
    {
        return $this->expiry_date && $this->expiry_date->isPast();
    }

    public function getIsExpiringSoonAttribute()
    {
        return $this->expiry_date && $this->expiry_date->diffInDays(now(), false) <= 0
            && $this->expiry_date->diffInDays(now(), false) >= -30;
    }
}
