<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * @property int $id
 * @property int $product_id
 * @property int|null $group_id
 * @property int $option_id
 * @property string $value
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 *
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue whereGroupId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue whereOptionId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientProductConfigOptionValue whereValue($value)
 *
 * @property-read \App\Models\ProductConfigFieldGroup|null $group
 * @property-read \App\Models\ProductConfigField|null $option
 * @property-read \App\Models\ClientProduct|null $product
 *
 * @mixin \Eloquent
 */
class ClientProductConfigOptionValue extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'product_id',
        'group_id',
        'option_id',
        'value',
    ];

    /**
     * Get the product that owns the option value.
     */
    public function product(): BelongsTo
    {
        return $this->belongsTo(ClientProduct::class, 'product_id');
    }

    /**
     * Get the config option group that owns the option value.
     */
    public function group(): BelongsTo
    {
        return $this->belongsTo(ProductConfigOptionGroup::class, 'group_id');
    }

    /**
     * Get the config option that owns the option value.
     */
    public function option(): BelongsTo
    {
        return $this->belongsTo(ProductConfigOption::class, 'option_id');
    }

    /**
     * Get the selected option value (the actual value selected by client).
     */
    public function selectedValue(): BelongsTo
    {
        return $this->belongsTo(ProductConfigOptionValue::class, 'value');
    }
}
