<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property int $id
 * @property string $description
 * @property string $improvement_type
 * @property bool $is_active
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Review> $reviews
 * @property-read int|null $reviews_count
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType whereDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType whereImprovementType($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType whereIsActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType withTrashed(bool $withTrashed = true)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ImprovementType withoutTrashed()
 * @mixin \Eloquent
 */
class ImprovementType extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'improvement_types';

    protected $guarded = [
        'id',
    ];

    protected $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime',
        'is_active'  => 'boolean',
    ];

    protected $fillable = [
        'description',
        'improvement_type',
        'is_active',
    ];

    public function reviews(): BelongsToMany
    {
        return $this->belongsToMany(
            Review::class,
            'review_improvements',
            'improvement_id',
            'review_id'
        );
    }
}
