<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;

class Group extends Model
{
    use HasFactory;

    protected $table = 'groups';

    protected $fillable = [
        'user_id',
        'name',
        'description',
        'color',
    ];

    public function validate($input = [])
    {
        $validator = Validator::make($input, [
            'name' => 'required',
        ]);

        return $validator;
    }

    public function numbers()
    {
        return $this->hasMany(Number::class, 'group_id');
    }

    public function number()
    {
        return $this->hasMany(Number::class, 'group_id');
    }

    public function getGroupNameAttribute()
    {
        return $this->attributes['name'] ?? null;
    }

    public function setGroupNameAttribute($value)
    {
        $this->attributes['name'] = $value;
    }
}
