<?php

namespace App\Modules\Sales\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class SalesReturn extends Model
{
    use BelongsToTenant;

    protected $table = 'sales_returns';

    protected $fillable = ['tenant_id', 'sales_order_id', 'status', 'correlation_id', 'actor_user_id', 'processed_at'];

    protected function casts(): array
    {
        return [
            'correlation_id' => 'string',
            'processed_at' => 'datetime',
        ];
    }

    public function salesOrder(): BelongsTo
    {
        return $this->belongsTo(SalesOrder::class, 'sales_order_id');
    }

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

    public function lines(): HasMany
    {
        return $this->hasMany(SalesReturnLine::class, 'sales_return_id');
    }
}
