﻿<?php

namespace App\Models;

use App\Traits\Scopes\ScopeActive;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Scopes\OrganisationScope;

/**
 * ExpensesCategory
 */
class ExpensesCategory extends Model
{
    use HasFactory, ScopeActive;

    /**
     * fillable
     *
     * @var array
     */
    protected $fillable = [
'organisation_id',
        'name',
        'desc',
        'status',
        'created_by',
        'updated_by'
    ];
    protected static function booted()
    {
        static::addGlobalScope(new OrganisationScope);

  // Automatically set the organisation_id before creating the model
        static::creating(function ($model) {
            if (auth()->check()) {
                $model->organisation_id = auth()->user()->organisation_id;
            }
        });
    }

    protected $appends = ['text'];

    // CONST
    public const STATUS_ACTIVE = 'active';
    public const STATUS_INACTIVE = 'inactive';


    // MUTATORS & ACCESSORS    
    /**
     * getTextAttribute
     *
     * @return void
     */
    public function getTextAttribute()
    {
        return $this->name;
    }