<?php

namespace App\Models;

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

class ShopCodeLog extends BaseModel
{
    use HasFactory;

    public $fillable = ['mobile', 'code_id', 'receive', 'user_id', 'name','type'];

    public const WINETYPE = "WINE";
    public const PACKTYPE = "PACK";

    public function scopeCode($query, $code_id)
    {
        return $query->where('code_id', $code_id);
    }

    public function scopeCodes($query, $code_ids)
    {
        return $query->whereIn('code_id', $code_ids);
    }

    public function scopeReceive($query)
    {
        return $query->where('receive',1);
    }

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

    public function shopCode()
    {
        return $this->belongsTo(ShopCode::class, 'code_id', 'id');
    }

    public function scopeWine()
    {
        return $this->where('type', self::WINETYPE);
    }

    public function scopePack()
    {
        return $this->where('type', self::PACKTYPE);
    }
}
