<?php

namespace App\Models;

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

class BrokerAccount extends Model
{
    protected $fillable = [
        'user_id',
        'broker',
        'is_market_feed_provider',
        'api_key',
        'api_secret',
        'client_id',
        'act_id',
        'access_token',
        'token_expires_at',
        'is_connected',
        'last_synced_at',
        'available_balance',
        'margin_used',
        'unrealized_pnl_total',
        'realized_pnl_total',
        'collateral',
        'sync_snapshot',
    ];

    protected function casts(): array
    {
        return [
            'api_secret' => 'encrypted',
            'access_token' => 'encrypted',
            'token_expires_at' => 'datetime',
            'is_connected' => 'boolean',
            'is_market_feed_provider' => 'boolean',
            'last_synced_at' => 'datetime',
            'sync_snapshot' => 'array',
        ];
    }

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