<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

// [INTEGRATION] Return of goods from a customer — mirrors Flutter CustomerReturnModel
class CustomerReturn extends Model
{
    use HasUlids, SoftDeletes;

    protected $fillable = [
        'user_id', 'store_id', 'local_id', 'order_id', 'invoice_number',
        'return_number', 'customer_id', 'customer_name', 'return_date',
        'total_amount', 'refund_method', 'status', 'reason', 'notes',
        'device_id', 'sync_version', 'is_deleted',
    ];

    protected $casts = [
        'total_amount' => 'float',
        'is_deleted' => 'boolean',
        'sync_version' => 'integer',
        'return_date' => 'date',
    ];

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

    public function items(): HasMany
    {
        return $this->hasMany(CustomerReturnItem::class, 'return_id');
    }
}
