<?php

namespace App\Providers;

use App\Models\Campaign;
use App\Models\Customer;
use App\Models\CustomerAddress;
use App\Models\Order;
use App\Models\OrderItem;
use App\Models\Outlet;
use App\Models\OutletCampaign;
use App\Models\OutletInventory;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\RawMaterial;
use App\Models\ReceiptItem;
use App\Models\Supplier;
use App\Models\User;
use App\Observers\SyncDeleteObserver;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Relation::morphMap([
            'product_variant' => ProductVariant::class,
            'raw_material' => RawMaterial::class,
        ]);

        $models = [
            Campaign::class,
            Outlet::class,
            OutletCampaign::class,
            User::class,
            Product::class,
            ProductVariant::class,
            RawMaterial::class,
            ReceiptItem::class,
            OutletInventory::class,
            Customer::class,
            CustomerAddress::class,
            Supplier::class
        ];

        foreach ($models as $model) {
            $model::observe(SyncDeleteObserver::class);
        }
    }
}
