<?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\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ChannelRechargeMethod
 * @property int id 主键
 * @property int department_id 所属部门/渠道
 * @property string account 银行账户
 * @property string currency 货币
 * @property string wallet_address 钱包地址
 * @property string qr_code 二维码
 * @property float rate 汇率
 * @property int type 支付类型
 * @property int user_id 管理员id
 * @property int user_name 管理员名称
 * @property int status 状态(0:禁用,1:启用)
 * @property string deleted_at 删除时间
 * @property string created_at 创建时间
 * @property string updated_at 最后一次修改时间
 *
 * @property AdminDepartment department
 * @property AdminUser user
 * @property ChannelRechargeMethodLang methodLang
 * @property ChannelRechargeSetting channelRechargeSetting
 * @package addons\webman\model
 */
class ChannelRechargeMethod extends Model
{
    use HasDateTimeFormatter, SoftDeletes, DataPermissions;

    //数据权限字段
    protected $dataAuth = ['department_id' => 'department_id'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->setTable(plugin()->webman->config('database.channel_recharge_method_table'));
    }

    /**
     * 部门
     * @return BelongsTo
     */
    public function department(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.department_model'), 'department_id')->withTrashed();
    }

    /**
     * 管理员用户
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.user_model'), 'user_id')->withTrashed();
    }

    /**
     * 多语言
     * @return hasMany
     */
    public function methodLang(): hasMany
    {
        return $this->hasMany(plugin()->webman->config('database.channel_recharge_method_lang_model'), 'method_id');
    }

    /**
     * 充值配置
     * @return hasMany
     */
    public function channelRechargeSetting(): hasMany
    {
        return $this->hasMany(plugin()->webman->config('database.channel_recharge_setting_model'), 'method_id');
    }
}
