<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Outlet extends Model
{
    protected $fillable = [
        'name',
        'location',
        'description',
    ];

    /**
     * Get the users/cashiers assigned to this outlet.
     */
    public function users(): HasMany
    {
        return $this->hasMany(User::class);
    }

    /**
     * Get the transactions for this outlet.
     */
    public function transactions(): HasMany
    {
        return $this->hasMany(Transaction::class);
    }

    /**
     * Get the stock records of ingredients for this outlet.
     */
    public function outletIngredients(): HasMany
    {
        return $this->hasMany(OutletIngredient::class);
    }

    /**
     * Get the ingredients used in this outlet.
     */
    public function ingredients(): BelongsToMany
    {
        return $this->belongsToMany(Ingredient::class, 'outlet_ingredients')
            ->withPivot('stock_qty', 'threshold_qty')
            ->withTimestamps();
    }

    /**
     * Get the retail products stocks tracked for this outlet.
     */
    public function outletProducts(): HasMany
    {
        return $this->hasMany(OutletProduct::class);
    }

    /**
     * Get the products tracked for this outlet.
     */
    public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class, 'outlet_products')
            ->withPivot('stock_qty', 'threshold_qty')
            ->withTimestamps();
    }
}
