<?php

namespace App\Models;

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

class Payout extends Model
{
    use HasFactory;

    protected $fillable = [
        'liner_id',
        'payment_method_id',
        'amount',
        'currency',
        'provider',
        'provider_reference',
        'failure_reason',
        'status',
        'requested_at',
        'paid_at',
        'metadata',
    ];

    protected function casts(): array
    {
        return [
            'amount' => 'decimal:2',
            'metadata' => 'array',
            'requested_at' => 'datetime',
            'paid_at' => 'datetime',
        ];
    }

    public function liner(): BelongsTo
    {
        return $this->belongsTo(User::class, 'liner_id');
    }

    public function paymentMethod(): BelongsTo
    {
        return $this->belongsTo(UserPaymentMethod::class, 'payment_method_id');
    }
}
