<?php

namespace App\Models;

use App\Support\Providers\ProviderCredentialKind;
use App\Support\Providers\ProviderCredentialSource;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ProviderCredential extends Model
{
    use HasFactory;

    protected $guarded = [];

    protected $hidden = [
        'payload',
    ];

    protected $casts = [
        'credential_kind' => ProviderCredentialKind::class,
        'source' => ProviderCredentialSource::class,
        'payload' => 'encrypted:array',
        'last_rotated_at' => 'datetime',
        'expires_at' => 'datetime',
    ];

    public function providerConnection(): BelongsTo
    {
        return $this->belongsTo(ProviderConnection::class, 'provider_connection_id');
    }
}
