<?php

namespace Modules\MedBilling\Entities;

use Illuminate\Database\Eloquent\Model;

/**
 * A pre-authorisation request to a payer for a planned service (SIFA P4-T1).
 */
class MedbillPreAuth extends Model
{
    protected $table = 'medbill_pre_auths';

    protected $guarded = ['id'];

    protected $casts = [
        'requested_amount' => 'decimal:4',
        'valid_until'      => 'date',
    ];

    public const STATUSES = ['requested', 'approved', 'denied', 'expired'];

    public function payer()
    {
        return $this->belongsTo(MedbillPayer::class, 'payer_id');
    }

    public function policy()
    {
        return $this->belongsTo(MedbillPatientPolicy::class, 'policy_id');
    }

    public function scopeForBusiness($query, $businessId)
    {
        return $query->where('business_id', $businessId);
    }
}
