<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Traits\LogsModelActivity;

class Branch extends Model
{
    /** @use HasFactory<\Database\Factories\ArtistFactory> */
    use HasFactory, LogsModelActivity;
    
    protected $fillable = [
        'name', 
        'external_ip',
        'enable',
    ];
    protected $casts = [
        'name' => 'string',
        'external_ip'=> 'string',
        'enable' => 'boolean',
    ];
    public function rooms() {
        return $this->hasMany(Room::class);
    }
    public function songs(){
        return $this->belongsToMany(Song::class)
                    ->withPivot('counts')
                    ->withTimestamps();
    }
    protected static function booted()
    {
        static::deleting(function (Branch $branch) {
            $branch->rooms()->delete();
        });
    }
}
