<?php

namespace Modules\ClinicCore\Entities;

use Illuminate\Database\Eloquent\Model;

/**
 * A treatment-package template (catalogue). business_id NULL = system default
 * available to every clinic; a per-business row shadows/extends it.
 */
class ClcTreatmentPackage extends Model
{
    protected $table = 'clc_treatment_packages';
    protected $guarded = ['id'];

    protected $casts = [
        'is_active'      => 'boolean',
        'total_sessions' => 'integer',
        'interval_days'  => 'integer',
        'price'          => 'decimal:2',
    ];

    public function scopeActive($q)
    {
        return $q->where('is_active', true);
    }

    /** System templates + this business's own packages. */
    public function scopeForBusiness($q, $businessId)
    {
        return $q->where(function ($qq) use ($businessId) {
            $qq->whereNull('business_id')->orWhere('business_id', $businessId);
        });
    }
}
