<?php

namespace App\Models;

use App\Traits\HasTranslations;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * @property int $id
 * @property int $option_id
 * @property string $value
 * @property int $order
 * @property bool $status
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\ProductConfigOption|null $option
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Pricing> $pricing
 * @property-read int|null $pricing_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\LanguageTranslation> $translations
 * @property-read int|null $translations_count
 *
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereOptionId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereOrder($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereTranslation(string $locale, string $field, string $value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereTranslationLike(string $locale, string $field, string $value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ProductConfigOptionValue whereValue($value)
 *
 * @mixin \Eloquent
 */
class ProductConfigOptionValue extends Model
{
    use HasFactory, HasTranslations;

    protected $fillable = [
        'option_id',
        'value',
        'order',
        'status',
        'passthrough_value',
        'is_default',
    ];

    protected $casts = [
        'order' => 'integer',
        'status' => 'boolean',
        'is_default' => 'boolean',
    ];

    /**
     * The attributes that are translatable.
     *
     * @var array<int, string>
     */
    protected $translatable = ['value'];

    public function option(): BelongsTo
    {
        return $this->belongsTo(ProductConfigOption::class, 'option_id');
    }

    public function pricing(): HasMany
    {
        return $this->hasMany(Pricing::class, 'relation_id')->where('type', 'product_config');
    }
}
