<?php
namespace App\Models;

use App\Scopes\OrganisationScope;
use Auth;
use Illuminate\Database\Eloquent\Model;

class BonusSetup extends Model
{
    protected $guarded = [];

    public function organisation()
    {
        return $this->belongsTo(Organisation::class);
    }

    public function payouts()
    {
        return $this->hasMany(BonusPayout::class);
    }
    protected $casts = [
        'formula' => 'array',
        'effective_start' => 'date',
        'effective_end' => 'date',
    ];

    protected static function booted()
    {
        static::addGlobalScope(new OrganisationScope());

        static::creating(function ($model) {
            if (Auth::check()) {
                $model->organisation_id = Auth::user()->organisation_id;
            }
        });
    }


}
