<?php

namespace Modules\User\Models;

use App\Models\Model;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class AccountRule extends Model
{

    use Cachable,
        SoftDeletes;

    protected $table = 'user_account_rules';

    public function logs(): HasMany
    {
        return $this->hasMany(AccountLog::class, 'rule_id');
    }

    /**
     * Notes   : 获取可执行次数的文本显示
     * @Date   : 2021/5/21 2:37 下午
     * @Author : < Jason.C >
     * @return string
     */
    protected function getTriggerTextAttribute(): string
    {
        switch ($this->trigger <=> 0) {
            case -1:
                return '仅一次';
            case 0:
                return '不限制';
            case 1:
                return $this->trigger . ' 次/日';
            default:
                return '';
        }
    }

}