<?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 to a supplier — mirrors Flutter SupplierReturnModel
class SupplierReturn extends Model
{
    use HasUlids, SoftDeletes;

    protected $fillable = [
        'user_id', 'store_id', 'local_id', 'supplier_id', 'supplier_name',
        'return_number', 'return_date', 'purchase_id', 'total_amount',
        '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(SupplierReturnItem::class, 'return_id');
    }
}
