<?php

namespace addons\webman\model;

use addons\webman\traits\DataPermissions;
use addons\webman\traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Class PlayGameRecord
 * @property int id 主键
 * @property int player_id 玩家id
 * @property int parent_player_id 上级玩家id
 * @property int platform_id 平台id
 * @property int game_code 游戏编号
 * @property int department_id 渠道id
 * @property int status 状态
 * @property float bet 押注
 * @property float win 输赢
 * @property float reward 奖金(不计入输赢)
 * @property string order_no 单号
 * @property string original_data 原始数据
 * @property string action_at 结算时间
 * @property string platform_action_at 结算时间(游戏平台)
 * @property string created_at 创建时间
 * @property string updated_at 最后一次修改时间
 * @property float deficit 亏损
 *
 * @property Channel channel 渠道
 * @property Player player 玩家
 * @property GamePlatform gamePlatform 平台信息
 * @package addons\webman\model
 */
class PlayGameRecord extends Model
{
    use HasDateTimeFormatter, DataPermissions;

    const STATUS_UNSETTLED = 0; // 未结算
    const STATUS_SETTLED = 1; // 已结算
    //数据权限字段
    protected $dataAuth = ['department_id' => 'department_id'];
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->setTable(plugin()->webman->config('database.play_game_record_table'));
    }

    /**
     * 渠道信息
     * @return BelongsTo
     */
    public function channel(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.channel_model'), 'department_id', 'department_id')->withTrashed();
    }

    /**
     * 玩家信息
     * @return BelongsTo
     */
    public function player(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.player_model'), 'player_id')->withTrashed();
    }

    /**
     * 平台信息
     * @return BelongsTo
     */
    public function gamePlatform(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.game_platform_model'), 'platform_id')->withTrashed();
    }
}
