<?php

namespace App\Models\Virtual;

use App\Core\Model;
use App\Models\HasCompositePrimaryKey;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Virtual\Relations\OrderRelations;

/**
 * App\Models\Virtual\OrderCard
 *
 * @property int $id
 * @property int $type
 * @property int $sim
 * @property int $order_id
 * @property int $company_id
 * @property int $package_id
 * @property int $counts
 * @property string|null $service_start_at
 * @property string|null $service_end_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string|null $deleted_at
 * @property-read \App\Models\Card\Card $card
 * @property-read \App\Models\Virtual\Company $company
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Virtual\Package[] $flowPackages
 * @property-read \App\Models\Virtual\Order $order
 * @property-read \App\Models\Virtual\Package $package
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Virtual\Package[] $renewalPackages
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Virtual\Package[] $renewals
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Virtual\OrderCard onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereCompanyId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereCounts($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard wherePackageId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereServiceEndAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereServiceStartAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereSim($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Virtual\OrderCard withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Virtual\OrderCard withoutTrashed()
 * @mixin \Eloquent
 * @property int $unit_price
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\OrderCard whereUnitPrice($value)
 */
class OrderCard extends Model
{
    use SoftDeletes, OrderRelations, HasCompositePrimaryKey;

    protected $table = 'virtual_order_cards';

    public function renewals()
    {
        return $this->belongsToMany(Package::class, 'virtual_order_renewal_cards', 'sim', 'package_id', 'sim', 'id')->withPivot('created_at', 'counts');
    }

    public function renewalPackages()
    {
        return $this->belongsToMany(Package::class, 'virtual_order_renewal_package_cards', 'sim', 'package_id', 'sim', 'id')->withPivot('created_at', 'counts');
    }

    public function flowPackages()
    {
        return $this->belongsToMany(Package::class, 'virtual_order_flows_package_cards', 'sim', 'package_id', 'sim', 'id')->withPivot('created_at', 'counts');
    }
}
