<?php

namespace App\Models;

use CodeIgniter\Model;

class Tiktok_model extends Model
{
    protected $table              = 'tiktok_videos';
    protected $primaryKey         = 'id';
    protected $returnType         = 'array';
    protected $useSoftDeletes     = false;
    protected $allowedFields      = ['judul_video', 'embed_code', 'status', 'created_at'];
    protected $useTimestamps      = false;
    protected $createdField       = 'created_at';
    protected $validationRules    = [];
    protected $validationMessages = [];
    protected $skipValidation     = false;

    // listing
    public function listing()
    {
        $builder = $this->db->table('tiktok_videos');
        $builder->orderBy('id', 'DESC');
        $query = $builder->get();

        return $query->getResultArray();
    }

    // total
    public function total()
    {
        $builder = $this->db->table('tiktok_videos');
        $builder->select('COUNT(*) AS total');
        $query = $builder->get();

        return $query->getRowArray();
    }

    // detail
    public function detail($id)
    {
        $builder = $this->db->table('tiktok_videos');
        $builder->where('id', $id);
        $query = $builder->get();

        return $query->getRowArray();
    }
}