<?php

namespace Yuvayana\AcadlixImporter\Models;

use Illuminate\Database\Eloquent\Model;

defined('ABSPATH') || exit();

if (!class_exists('ImporterSync')) {
  class ImporterSync extends Model
  {
    const FROM_WP_PRO_QUIZ = 'wp-pro-quiz';
    const FROM_WP_ADV_QUIZ = 'wp-adv-quiz';
    protected $table;

    protected $fillable = [
      'old_id',
      'new_id',
      'type',
      'meta_key',
      'meta_value',
      "from",
    ];

    public function __construct($attributes = [])
    {
      parent::__construct($attributes);
      $this->table = acadlix()->helper()->acadlix_table_prefix("importer_sync");
    }

    public function scopeOfCategory($query)
    {
      return $query->where("type", "category");
    }

    public function scopeOfQuizCategory($query)
    {
      return $query->where("type", "category")->where("meta_key", "category_type")->where("meta_value", "quiz");
    }

    public function scopeOfQuestionCategory($query)
    {
      return $query->where("type", "category")->where("meta_key", "category_type")->where("meta_value", "question");
    }

    public function scopeOfMaster($query)
    {
      return $query->where("type", "master");
    }

    public function scopeOfQuestion($query)
    {
      return $query->where("type", "question");
    }

    public function scopeOfPrerequisite($query)
    {
      return $query->where("type", "prerequisite");
    }

    public function scopeOfStatistic($query)
    {
      return $query->where("type", "statistic");
    }

    public function scopeOfStatisticRef($query)
    {
      return $query->where("type", "statistic_ref");
    }

    public function scopeOfToplist($query)
    {
      return $query->where("type", "toplist");
    }

    public function scopeOfPost($query)
    {
      return $query->where("type", "post");
    }

    public function scopeOfWpProQuiz($query)
    {
      return $query->where("from", self::FROM_WP_PRO_QUIZ);
    }

    public function scopeOfWpAdvQuiz($query)
    {
      return $query->where("from", self::FROM_WP_ADV_QUIZ);
    }
  }
}