<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Laravel\Cashier\Subscription;

class SubscriptionConfigSelection extends Model
{
    protected $fillable = [
        'subscription_id',
        'option_id',
        'value_id',
        'quantity',
        'text_value',
        'locked_price',
        'locked_hourly_price',
        'billing_cycle',
        'is_custom_build',
    ];

    protected function casts(): array
    {
        return [
            'quantity' => 'integer',
            'locked_price' => 'decimal:4',
            'locked_hourly_price' => 'decimal:4',
            'is_custom_build' => 'boolean',
        ];
    }

    public function subscription(): BelongsTo
    {
        return $this->belongsTo(Subscription::class);
    }

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

    public function value(): BelongsTo
    {
        return $this->belongsTo(PlanConfigValue::class, 'value_id');
    }
}
