<?php
namespace model;

use model\database;


class categories {
    
    public static function get_category_by_id(int $cid) {
        return (new database())->table('categories')->where(['cid' => $cid])->select();
    }
    
    public static function del_category_by_id(int $cid) {
        return (new database())->table('categories')->where(['cid' => $cid])->delete();
    }
    
    public static function add_category($name) {
        return (new database())->table('categories')->insert(['name' => $name]);
    }
    
    public static function update_category(int $cid, $name) {
        return (new database())->table('categories')->where(['cid' => $cid])->update(['name' => $name]);
    }
    
    public static function get_categories() {
        $categories = (new database())->table('categories')->select();
        return isset($categories[0]['cid']) ? $categories : [$categories];
    }
    
    public static function list_categories(int $page = 1) {
        $categories = (new database())->table('categories')->page(20, $page);
        return isset($categories[0]['cid']) ? $categories : [$categories];
    }
    
    public static function count_categories() {
        return (new database())->table('categories')->count();
    }
    
}
