<?php

namespace App\Models;

use App\Traits\ModelCounterTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class AppointmentCategory extends Model
{
    use HasFactory, SoftDeletes, ModelCounterTrait;

    protected $fillable = [
        'code',
        'title',
        'color'
    ];

    public function appointments()
    {
        return $this->hasMany(Appointment::class);
    }

    public static function booted(): void {
        static::creating(function(AppointmentCategory $category) {
            $category->code = $category->codeGenerator([
                "prefix" => "RDC",
                "model" => "AppointmentCategory",
                "length" => 5,
            ]);
        });
    }
}
