<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;

class Organisation extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'email',
        'address',
        'date_founded',
        'monthly_payroll',
        'bi_weekly_payroll',
        'special_payroll',
        'industry',
        'logo',
        'phone',
        'is_active',
        'plan_id',
        'subscription_id',
        'description'
    ];

    protected $dates = ['deleted_at'];

    use LogsActivity;


    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logAll()
            ->useLogName('Organisation')
            ->logOnlyDirty()
            ->setDescriptionForEvent(fn(string $eventName) => "Organisation has been {$eventName}")
            ->dontSubmitEmptyLogs();
    }

    ///Define Org Parent reletionship
    public function user(): HasOne
    {
        return $this->hasOne(User::class);
    }
    public function organisationActivity(): HasOne
    {
        return $this->hasOne(OrganisationActivity::class);
    }
    public function division(): HasOne
    {
        return $this->hasOne(Division::class);
    }

    public function holiday(): HasOne
    {
        return $this->hasOne(Holiday::class);
    }
    public function departments(): HasMany
    {
        return $this->hasMany(OrganisationDepartment::class);
    }
    public function employmentType(): HasOne
    {
        return $this->hasOne(EmploymentType::class);
    }
    public function subscription(): HasOne
    {
        return $this->hasOne(Subscription::class)->latest();
    }
    public function subscriptionTransaction(): HasOne
    {
        return $this->hasOne(SubscriptionTransactions::class);
    }
    public function orgPermissions()
    {
        return $this->hasMany(UserOrgPermission::class);
    }
    public function organisationTaxSetting()
    {
        return $this->hasMany(OrganisationTaxSetting::class);
    }
    public function organisationTaxEmployee()
    {
        return $this->hasMany(OrganisationTaxEmployee::class);
    }
    public function organisationAllowanceEmployee(): HasMany
    {
        return $this->hasMany(OrganisationEmployeeAllowance::class);
    }

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

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

    public function productOrganisation()
    {
        return $this->hasMany(ProductOrganisation::class);
    }
    public function managerUser()
    {
        return $this->hasMany(ManagerUser::class);
    }
    public function leaveRequest()
    {
        return $this->hasMany(LeaveRequest::class);
    }
    public function expenseApproval()
    {
        return $this->hasMany(ExpenseApproval::class);
    }
    public function leaveFee()
    {
        return $this->hasMany(LeaveFee::class);
    }
    public function employeeTransfer()
    {
        return $this->hasMany(EmployeeTransfer::class);
    }
    public function disciplinaryAction()
    {
        return $this->hasMany(DisciplinaryAction::class);
    }
    public function groupAccountOrganisation()
    {
        return $this->hasMany(GroupAccountOrganisation::class);
    }
}
