<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

/**
 * Bet
 * @mixin Builder
 * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
 */
class Issue extends Authenticatable
{
    use HasApiTokens, Notifiable;
    protected $table = 'issues';
    // protected $hidden = ['created_at', 'updated_at'];
    protected $fillable = ['issue_no', 'start_time', 'end_time' ,'winning_numbers' ,'status' ,'combo', 'extreme', 'image'];

    const STATUS_DRAFT = 0;
    const STATUS_BETTING = 1;
    const STATUS_CLOSE = 2;
    const STATUS_DRAW = 3;

    public static $STATUS = [
        0 => '草稿',
        1 => '投注中',
        2 => '封盘',
        3 => '开奖',
    ];

    public static function getStatus($val = -1)
    {
        $array = self::$STATUS;
        if($val < 0){
            $arr = [];
            foreach($array as $k => $v){
                $item = [];
                $item['id'] = $k;
                $item['title'] = $v;
                $arr[] = $item;
            }
            return $arr;
        }else{
            return $array[$val];
        }
    }

    protected function getCreatedAtAttribute($value)
    {
        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
    }

    protected function getUpdatedAtAttribute($value)
    {
        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
    }

    // public function children()
    // {
    //     return $this->hasMany(Menu::class, 'parent_id');
    // }

    // public function parent()
    // {
    //     return $this->belongsTo(Menu::class, 'parent_id');
    // }
}