<?php

namespace App\Models;

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

class SaasCheckoutIntent extends Model
{
    protected $table = 'saas_checkout_intents';

    protected $fillable = [
        'reference',
        'plan_id',
        'empresa_nombre',
        'empresa_slug',
        'empresa_email',
        'admin_nombre',
        'admin_email',
        'admin_password_hash',
        'currency',
        'amount_in_cents',
        'estado',
        'wompi_transaction_id',
        'wompi_status',
        'last_event_at',
        'paid_at',
        'empresa_id',
        'suscripcion_id',
        'provisioned_at',
        'failure_reason',
    ];

    protected function casts(): array
    {
        return [
            'last_event_at' => 'datetime',
            'paid_at' => 'datetime',
            'provisioned_at' => 'datetime',
            'created_at' => 'datetime',
            'updated_at' => 'datetime',
        ];
    }

    public function suscripcion(): BelongsTo
    {
        return $this->belongsTo(Suscripcion::class, 'suscripcion_id');
    }
    public function plan(): BelongsTo
    {
        return $this->belongsTo(Plan::class, 'plan_id');
    }
    public function empresa(): BelongsTo
    {
        return $this->belongsTo(Empresa::class, 'empresa_id');
    }
}
