<?php

namespace App\Models;

use App\Enums\OutletStatus;
use Dyrynda\Database\Support\CascadeSoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use Veelasky\LaravelHashId\Eloquent\HashableId;

class Outlet extends Model implements HasMedia
{
    use CascadeSoftDeletes, HasFactory, HashableId, HasSlug, InteractsWithMedia, SoftDeletes;

    protected $guarded = ['id'];

    protected $cascadeDeletes = ['openingHours', 'facilities', 'vouchers', 'perfumes', 'products', 'bottles', 'expenses', 'users'];

    protected function casts(): array
    {
        return [
            'status' => OutletStatus::class,
        ];
    }

    public function getSlugOptions(): SlugOptions
    {
        return SlugOptions::create()
            ->generateSlugsFrom('name')
            ->saveSlugsTo('slug');
    }

    public function openingHours(): HasMany
    {
        return $this->hasMany(OpeningHour::class);
    }

    public function facilities(): HasMany
    {
        return $this->hasMany(Facility::class);
    }

    public function vouchers(): BelongsToMany
    {
        return $this->belongsToMany(Voucher::class);
    }

    public function perfumes(): BelongsToMany
    {
        return $this->belongsToMany(Perfume::class);
    }

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

    public function bottles(): BelongsToMany
    {
        return $this->belongsToMany(Bottle::class);
    }

    public function expenses(): HasMany
    {
        return $this->hasMany(Expense::class);
    }

    public function users(): BelongsToMany
    {
        return $this->belongsToMany(User::class);
    }

    public function purchases(): HasMany
    {
        return $this->hasMany(Purchase::class);
    }

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