<?php

namespace Modules\MedAccounting\Entities;

use Illuminate\Database\Eloquent\Model;

/**
 * A cost centre (SIFA P7-T2) — department / facility / project used to allocate
 * journal lines for departmental P&L. `ref_id` optionally binds to a ClinicCore
 * department or an ERP business_location.
 */
class MedaccCostCenter extends Model
{
    protected $table = 'medacc_cost_centers';

    protected $guarded = ['id'];

    protected $casts = [
        'is_active' => 'boolean',
    ];

    public const TYPES = ['department', 'facility', 'project', 'other'];

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

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

    public function lines()
    {
        return $this->hasMany(MedaccJournalLine::class, 'cost_center_id');
    }
}
