<?php
/**
 * Created by PhpStorm.
 * User: ntaylor-visionware
 * Date: 11/15/17
 * Time: 10:46 AM
 */

namespace Hilco\Models;

class PromotionCustomerTrigger_Customer extends WebModel {
    protected $table = 'PromotionCustomerTrigger_Customer';
    protected $fillable = ['excluded', 'redeemed', 'temporary_email', 'commit_sequence'];

    public function promotionCustomerTrigger() {
        return $this->belongsTo(PromotionCustomerTrigger::class,
                            'promotioncustomertrigger_id', 'id');
    }

    public function customer() {
        return $this->belongsTo(Customer::class, 'customer_id', 'id');
    }

    public function scopeTriggerCustomer($query, $trigger_id, $customer_id) {
        return $query
            ->where('promotioncustomertrigger_id', $trigger_id)
            ->where('customer_id', $customer_id)
        ;
    }

    public function scopeByCustomer($query, $customer_id) {
        return $query
            -> where('customer_id', $customer_id)
        ;
    }

    public function scopeByTrigger($query, $trigger_id) {
        return $query
            -> where('promotioncustomertrigger_id', $trigger_id)
        ;
    }

    use HasCommitSequence;
}