<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ActivityOrderLog extends BaseModel
{
    use HasFactory,SoftDeletes;
    protected $table = "activity_order_log";

    public const REFUND_TYPE = "REFUND";
    public const SIGNIN_TYPE = "SIGNIN";
    public const ORDER_TYPE = "ORDER";
    public const NOREFUND_TYPE = 'NO_REFUND';

    public static function addActivityOrderLog($user_id,$order_id = 0,$amount,$remark,$admin_id=null,$admin_name = null,$type=null){
        $log = self::create(['user_id'=>$user_id,'order_id'=>$order_id,'amount'=>$amount,'remark'=>$remark,'admin_id'=>$admin_id,'admin_name'=>$admin_name, 'type'=>$type]);
        return $log;
    }

    public function activityOrder()
    {
        return $this->hasOne(ActivityOrder::class, 'id', 'order_id');
    }

    public function scopeOwner($query, $user_id)
    {
        return $query->where("user_id", $user_id);
    }
}
