<?php

namespace App\Models\Returns;

use App\Models\Branch;
use App\Models\Concerns\Auditable;
use App\Models\Concerns\BelongsToTenant;
use App\Models\Concerns\BranchScoped;
use App\Models\Customers\Customer;
use App\Models\Lookups\Status;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class ReturnDoc extends Model
{
    use Auditable, BelongsToTenant, BranchScoped, SoftDeletes;

    protected $table = 'returns';

    protected $fillable = [
        'return_number', 'customer_id', 'branch_id',
        'status_id', 'total', 'refund_method_id', 'refund_amount', 'note',
    ];

    protected function casts(): array
    {
        return [
            'total' => 'decimal:2',
            'refund_amount' => 'decimal:2',
        ];
    }

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

    public function branch(): BelongsTo
    {
        return $this->belongsTo(Branch::class, 'branch_id');
    }

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

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

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