<?php

namespace App\Models;

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

class SubscriptionTransfer extends Model
{
    use HasFactory;

    protected $fillable = [
        'subscription_id',
        'from_customer_id',
        'to_customer_id',
        'transferred_by',
        'transfer_date',
        'reason',
        'old_data',
        'new_data'
    ];

    protected $casts = [
        'transfer_date' => 'date',
        'old_data' => 'array',
        'new_data' => 'array'
    ];

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

    public function fromCustomer(): BelongsTo
    {
        return $this->belongsTo(Customer::class, 'from_customer_id');
    }

    public function toCustomer(): BelongsTo
    {
        return $this->belongsTo(Customer::class, 'to_customer_id');
    }

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

}
