<?php

namespace App\Models;

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

class Merchant extends Model
{
    use HasFactory;

    protected $table = 'merchants';

    protected $fillable = [
        'name', 'slug', 'domain', 'contact_name', 'contact_phone', 'contact_email',
        'plan', 'status', 'trial_ends_at', 'activated_at', 'settings',
    ];

    protected $casts = [
        'trial_ends_at' => 'datetime',
        'activated_at' => 'datetime',
        'settings' => 'array',
    ];

    public function admins(): HasMany
    {
        return $this->hasMany(Admin::class, 'merchant_id');
    }

    public function users(): HasMany
    {
        return $this->hasMany(User::class, 'merchant_id');
    }

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

    public function orders(): HasMany
    {
        return $this->hasMany(Order::class, 'merchant_id');
    }

    public function categories(): HasMany
    {
        return $this->hasMany(ProductCategory::class, 'merchant_id');
    }
}
