<?php

namespace App\Models;

use App\Observers\BarbershopObserver;
use Dyrynda\Database\Support\CascadeSoftDeletes;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\SoftDeletes;

#[ObservedBy([BarbershopObserver::class])]
class Barbershop extends Model
{
    use CascadeSoftDeletes, HasFactory, SoftDeletes;

    protected $table = 'barbershop';

    protected $fillable = [
        'name',
        'contact_number',
        'landmark',
        'address',
        'opened',
        'closed',
        'cash',
    ];

    protected $cascadeDeletes = [
        'users',
        'customers',
        'services',
        'attendances',
        'expenses',
        'inventory',
        'transactions',
        'payrolls',
        'cash',
        'attachment',
    ];

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

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

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

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

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

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

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

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

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

    public function attachment(): MorphOne
    {
        return $this->morphOne(Attachment::class, 'attachmentable');
    }
}
