<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CheckinHistory extends Model
{
    use HasFactory;

    public $timestamps = false;

    protected $fillable = [
        'user_id',
        'in_or_out',
        'image',
        'checkin_at_time',
        'flag',
        'temperature',
        'remote_addr',
##K.Nakazaki 2023/06/29 開始
        'device',
        'old_user_id',
        'face_change_at',
        'face_change_id',
##K.Nakazaki 2023/06/29 終了
    ];

    protected $appends = [
        'date',
        'hour',
    ];

    protected $casts = [
        'checkin_at_time' => 'datetime:Y-m-d H:i:s',
    ];

    #region Accessor, Mutator.
    public function getDateAttribute()
    {
        return date('Y/m/d', strtotime($this->attributes['checkin_at_time']));
    }

    public function getHourAttribute()
    {
        return date('H:i:s', strtotime($this->attributes['checkin_at_time']));
    }
    #endregion

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function userWithTrashed()
    {
        return $this->belongsTo(User::class, 'user_id')->withTrashed();
    }
}
