<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * One row per fully-qualified pricing tuple:
 * `(plan, currency, gateway, period)` → `(amount_minor, provider_price_id)`.
 *
 * Replaces `PlanProviderLink` — that model conflated the gateway price-id
 * mapping with a per-link display amount/currency override. `PlanPrice`
 * keeps one source of truth: every billable shape a plan can take is one
 * row, with both the amount the customer pays and the gateway's reference
 * id needed to actually charge it.
 */
#[Fillable([
    'plan_id',
    'currency_id',
    'gateway_key',
    'period',
    'amount_minor',
    'provider_price_id',
    'is_active',
])]
class PlanPrice extends Model
{
    protected function casts(): array
    {
        return [
            'plan_id' => 'integer',
            'currency_id' => 'integer',
            'amount_minor' => 'integer',
            'is_active' => 'boolean',
        ];
    }

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

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