<?php

namespace App\Models;

use App\Scopes\UserScope;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserRechargeRecord.
 *
 * @property int                        $id         id
 * @property int                        $user_id    user_id
 * @property int                        $combo_id   套餐ID
 * @property string                     $price      支付金额 1:1 金币
 * @property float                      $gift       赠送金币
 * @property int                        $pay_id     支付ID
 * @property \Illuminate\Support\Carbon $updated_at 删除时间
 * @property string                     $deleted_at 删除时间
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord query()
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereComboId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereGift($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord wherePayId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord wherePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereUserId($value)
 *
 * @mixin \Eloquent
 *
 * @property \App\Models\RechargeCombo|null $combo
 * @property \App\Models\User|null          $user
 * @property float                          $gold  充值奖励金币
 * @property \App\Models\Pay|null           $pay
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereGold($value)
 *
 * @property int $status 充值状态
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereStatus($value)
 *
 * @property string $desc 说明
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord filterUser()
 * @method static \Illuminate\Database\Eloquent\Builder|UserRechargeRecord whereDesc($value)
 */
class UserRechargeRecord extends Model
{
    use HasFactory;
    use UserScope;

    protected $casts = [
        'gold' => 'integer',
        'gift' => 'integer',
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function combo()
    {
        return $this->belongsTo(RechargeCombo::class, 'combo_id', 'id');
    }

    public function pay()
    {
        return $this->belongsTo(Pay::class, 'pay_id', 'pay_id');
    }
}
