<?php

namespace App\Models;

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

class OrderExchange extends Model
{
    use HasFactory;

    protected $guarded = [];

    protected $casts = [
        'returned_amount' => 'float',
        'replacement_amount' => 'float',
        'difference_amount' => 'float',
        'affects_collectable' => 'boolean',
        'exchanged_at' => 'datetime',
        'voided_at' => 'datetime',
    ];

    public function order()
    {
        return $this->belongsTo(Order::class);
    }

    public function customer()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function items()
    {
        return $this->hasMany(OrderExchangeItem::class);
    }

    public function createdByAdmin()
    {
        return $this->belongsTo(Admin::class, 'created_by_admin_id');
    }

    public function voidedByAdmin()
    {
        return $this->belongsTo(Admin::class, 'voided_by_admin_id');
    }
}
