<?php

namespace App\Models\Account;

use App\AdminUser;
use App\Models\AccountsInfo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class UserBlacklist extends Model
{
    public const CREATED_AT = 'CreatedAt';

    public const UPDATED_AT = 'UpdatedAt';

    protected $table = 'QPAccountsDB.dbo.UserBlacklist';

    protected $primaryKey = 'ID';

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('soft_delete', function (Builder $b) {
            $b->where('IsDel', 0);
        });
    }

    public function accountsInfo()
    {
        return $this->belongsTo(AccountsInfo::class, 'UserID', 'UserID');
    }

    public function admin()
    {
        return $this->belongsTo(AdminUser::class, 'AdminID', 'id');
    }

    public function getCreatedAtChinaAttribute()
    {
        return date('Y-m-d H:i:s', strtotime($this->attributes['CreatedAt'].' +11 hours'));
    }

    public function getUpdatedAtChinaAttribute()
    {
        return date('Y-m-d H:i:s', strtotime($this->attributes['UpdatedAt'].' +11 hours'));
    }
}
