<?php

namespace App\Models\Finance;

use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class FinanceCategory extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'parent_id', 'name', 'type', 'level', 'sort', 'status',
    ];

    protected function casts(): array
    {
        return [
            'type' => 'integer',
            'level' => 'integer',
            'sort' => 'integer',
            'status' => 'integer',
        ];
    }

    public function children(): HasMany
    {
        return $this->hasMany(self::class, 'parent_id');
    }

    public function parent(): BelongsTo
    {
        return $this->belongsTo(self::class, 'parent_id');
    }
}
