<?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;
use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
 * Class PlayerBank
 * @property int id 主键
 * @property int player_id 玩家id
 * @property int department_id 渠道id
 * @property int type 類型
 * @property int record_type 记录类型
 * @property float amount 金额
 * @property float chip_amount 打碼量
 * @property float before_chip_amount 調整前打碼量
 * @property float after_chip_amount 調整後打碼量
 * @property float must_chip_amount gift打碼量
 * @property float before_must_chip_amount 調整前gift打碼量
 * @property float after_must_chip_amount 調整後gift打碼量
 * @property string source_type 來源
 * @property int source_id 來源id
 * @property string created_at 创建时间
 * @property string updated_at 最后一次修改时间
 *
 * @property Player player 玩家
 * @property Channel channel 渠道
 * @package addons\webman\model
 */
class PlayerChipRecord extends Model
{
    use HasDateTimeFormatter, DataPermissions;

    //数据权限字段
    protected $dataAuth = ['department_id' => 'department_id'];
    const TYPE_INC = 1; // 增加
    const TYPE_DEC = 2; // 减少

    const RECORD_TYPE_SIGN = 1; // 签到
    const RECORD_TYPE_RECHARGE = 2; // 充值
    const RECORD_TYPE_ACTIVITY = 3; // 活动
    const RECORD_TYPE_GAME = 4; // 游戏
    const RECORD_TYPE_COMMISSION = 5; // 分润
    const RECORD_TYPE_BANKRUPTCY = 6; // 破产
    const RECORD_TYPE_BET_REBATE = 7; // 打码返水
    const RECORD_TYPE_FIRST_RECHARGE_REWARD = 8; // 首充奖励

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->setTable(plugin()->webman->config('database.player_chip_record_table'));
    } // 減少

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

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

    /**
     * 来源
     * @return MorphTo
     */
    public function source(): MorphTo
    {
        return $this->morphTo();
    }
}
