<?php

namespace App\Models;

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

class Supplier extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'company_name',
        'registration_number',
        'vat_number',
        'contact_name',
        'contact_phone',
        'contact_email',
        'address',
        'city',
        'province',
        'postal_code',
        'country',
        'description',
        'logo_url',
        'banner_url',
        'delivery_self',
        'delivery_platform',
        'delivery_collection',
        'registration_fee_paid',
        'registration_fee_amount',
        'commission_rate',
        'is_verified',
        'is_featured',
        'rating',
        'total_reviews',
    ];

    protected $casts = [
        'delivery_self' => 'boolean',
        'delivery_platform' => 'boolean',
        'delivery_collection' => 'boolean',
        'registration_fee_paid' => 'boolean',
        'is_verified' => 'boolean',
        'is_featured' => 'boolean',
        'registration_fee_amount' => 'decimal:2',
        'commission_rate' => 'decimal:2',
        'rating' => 'decimal:2',
    ];

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

    public function products()
    {
        return $this->hasMany(Product::class);
    }

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

    public function transactions()
    {
        return $this->hasMany(SupplierTransaction::class);
    }

    public function getDeliveryOptionsAttribute()
    {
        $options = [];
        if ($this->delivery_self) $options[] = 'supplier_delivery';
        if ($this->delivery_platform) $options[] = 'platform_delivery';
        if ($this->delivery_collection) $options[] = 'collection';
        return $options;
    }
}
