<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class UserPaymentMethod extends Model
{
    use HasFactory;

    public const TYPE_PAY_IN = 'pay_in';
    public const TYPE_PAY_OUT = 'pay_out';

    protected $fillable = [
        'user_id',
        'type',
        'provider',
        'label',
        'account_holder',
        'details',
        'is_default',
        'is_active',
        'verified_at',
    ];

    protected function casts(): array
    {
        return [
            'details' => 'array',
            'is_default' => 'boolean',
            'is_active' => 'boolean',
            'verified_at' => 'datetime',
        ];
    }

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

    public function payments(): HasMany
    {
        return $this->hasMany(Payment::class, 'payment_method_id');
    }

    public function payouts(): HasMany
    {
        return $this->hasMany(Payout::class, 'payment_method_id');
    }
}
