<?php

namespace Modules\Posts\Models;

use CodeIgniter\Model;

class TagsModel extends Model
{

  protected $table = 'tags';
    protected $primaryKey = 'id';

    protected $allowedFields = ['name', 'alias', 'description', 'status', 'updated_at'];

    protected $returnType     = 'array';
    protected $useTimestamps  = true;
    protected $useSoftDeletes = true;
    
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';

    public function getAll()
    {
        $builder = $this->db->table('tags');
        $builder->where('deleted_at', null);
        $results = $builder->get()->getResult();
        return $results;
    }

    //Used in selectize
    public function getAllTags()
    {
        $builder = $this->db->table('tags');
        $builder->where('deleted_at', null);
        $results = $builder->get()->getResultArray(); // Retrieve results as an array
        return $results;
    }

    //Get Single Tag
    public function getSingleTag($id)
    {
      $builder = $this->db->table('tags');
      $builder->where('id', $id);
      $builder->orWhere('alias', $id);
      $results = $builder->get()->getRow();
      return $results;
    }

    //Get Single Tag
    public function checkSingleTag($id)
    {
      $builder = $this->db->table('tags');
      $builder->where('id', $id);
      $builder->orWhere('alias', $id);
      $results = $builder->get()->getRow();
      return $results;
    }

}