<?php

namespace App\Models;

use App\Casts\Hash;
use App\Models\BaseModel;
use App\Scopes\CompanyScope;
use App\Classes\CommonHrm;
use App\Classes\Common;
use Carbon\Carbon;

class ShiftAssignment extends BaseModel
{
    protected $table = 'shift_assignments';

    protected $default = ['xid', 'x_user_id', 'x_shift_id','clock_in_time', 'clock_out_time','date','name', 'late_mark_after', 'early_clock_in_time', 'allow_clock_out_till'];

    protected $guarded = ['id','created_at','updated_at'];

    protected $hidden = ['id', 'user_id', 'shift_id'];

    protected $appends = ['xid', 'x_user_id', 'x_shift_id'];

    protected $filterable = ['id'];

    protected $hashableGetterFunctions = [
        'getXUserIdAttribute' => 'user_id',
        'getXShiftIdAttribute' => 'shift_id',
    ];

    protected $casts = [
        'user_id' => Hash::class . ':hash',
        'shift_id' => Hash::class . ':hash',
        'date' => 'date:Y-m-d',
        'late_mark_after' => 'integer',
        'early_clock_in_time' => 'integer',
        'allow_clock_out_till' => 'integer',
        'day_off_data' => 'boolean',
    ];
    protected $permissions = ['shift_assignments_view'];

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope(new CompanyScope);
    }

    public function user()
    {
        return $this->hasOne(StaffMember::class, 'id', 'user_id');
    }

    public function shift()
    {
        return $this->hasOne(Shift::class, 'id', 'shift_id');
    }

      public function attedanceShift()
    {
        return $this->belongsTo(Shift::class, 'shift_id', 'id');
    }
}
