<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;

/**
 * @property int $id
 * @property string $slug
 * @property string $name
 * @property string|null $category
 * @property string|null $expected_unit
 * @property string|null $description
 * @property string|null $image_url
 * @property bool $is_active
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @property-read Collection<int, PriceObservation> $observations
 * @property-read int|null $observations_count
 * @property-read Collection<int, StoreProductTarget> $targets
 * @property-read int|null $targets_count
 *
 * @method static Builder<static>|BasicBasketProduct active()
 * @method static \Database\Factories\BasicBasketProductFactory factory($count = null, $state = [])
 * @method static Builder<static>|BasicBasketProduct newModelQuery()
 * @method static Builder<static>|BasicBasketProduct newQuery()
 * @method static Builder<static>|BasicBasketProduct query()
 * @method static Builder<static>|BasicBasketProduct whereCategory($value)
 * @method static Builder<static>|BasicBasketProduct whereCreatedAt($value)
 * @method static Builder<static>|BasicBasketProduct whereDescription($value)
 * @method static Builder<static>|BasicBasketProduct whereExpectedUnit($value)
 * @method static Builder<static>|BasicBasketProduct whereId($value)
 * @method static Builder<static>|BasicBasketProduct whereIsActive($value)
 * @method static Builder<static>|BasicBasketProduct whereName($value)
 * @method static Builder<static>|BasicBasketProduct whereSlug($value)
 * @method static Builder<static>|BasicBasketProduct whereUpdatedAt($value)
 *
 * @mixin \Eloquent
 */
class BasicBasketProduct extends Model
{
    use HasFactory;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'slug',
        'name',
        'category',
        'expected_unit',
        'description',
        'image_url',
        'is_active',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
        ];
    }

    public function scopeActive(Builder $query): Builder
    {
        return $query->where('is_active', true);
    }

    public function targets(): HasMany
    {
        return $this->hasMany(StoreProductTarget::class);
    }

    public function observations(): HasMany
    {
        return $this->hasMany(PriceObservation::class);
    }
}
