<?php

namespace App\Models;

use CodeIgniter\Model;

class CountryModel extends Model
{
    protected $table = 'countries';
    protected $primaryKey = 'id';

    protected $allowedFields = ['sortname', 'name', 'slug', 'phoncode', 'status'];

    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('countries');
        return $result = $builder->get()->getResult();
    }

    public function getById($id)
    {
        $builder = $this->db->table('countries');
        $builder->where('deleted_at', null);
        $builder->where('id', $id);
        return $result = $builder->get()->getRow();
    }
}