<?php

namespace Modules\User\Models;

use App\Models\Model;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;

class SignConfig extends Model
{

    use Cachable;

    const TYPE_SINGLE     = 'single';
    const TYPE_CONTINUOUS = 'continuous';
    const TYPE_CYCLE      = 'cycle';
    const TYPES           = [
        self::TYPE_SINGLE     => '单日',
        self::TYPE_CONTINUOUS => '连续',
        self::TYPE_CYCLE      => '周期连续',
    ];
    const SHOWTYPES_DAY   = 'day';
    const SHOWTYPES_WEEK  = 'week';
    const SHOWTYPES_MONTH = 'month';
    const SHOWTYPES       = [
        self::SHOWTYPES_DAY   => '7天展示',
        self::SHOWTYPES_WEEK  => '一周展示',
        self::SHOWTYPES_MONTH => '一月展示',
    ];
    protected $table = 'user_sign_configs';
    protected $casts = [
        'params' => 'json',
        'tasks'  => 'json',
    ];

    public static function getParams($key = '')
    {
        $model = SignConfig::find(1);
        if (! $key) {
            return collect($model->params);
        } else {
            return $model->params[$key] ?? '';
        }
    }

    public static function getTasks($key = '')
    {
        $model = SignConfig::find(1);
        if (! $key) {
            return collect($model->tasks);
        } else {
            return $model->tasks[$key] ?? '';
        }
    }

}