<?php

namespace App\Models;

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

class Order extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'invoice_number',
        'status',
        'total',
        'shipping_cost',
        'voucher_id',
        'discount_amount',
        'shipping_address',
        'cancel_reason',
        'payment_type',
        'dp_amount',
        'remaining_payment',
        'dp_status',
        'tax_amount'
    ];

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

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

    public function payment()
    {
        return $this->hasOne(Payment::class);
    }

    public function shipment()
    {
        return $this->hasOne(Shipment::class);
    }

    public function voucher()
    {
        return $this->belongsTo(Voucher::class);
    }

    public function affiliateCommissions()
    {
        return $this->hasMany(AffiliateCommission::class);
    }

    public function subscriptions()
    {
        return $this->hasMany(Subscription::class);
    }
}
