<?php

use Jaga\Models\BaseModel;

class RelInstansiWilayah extends BaseModel {
    public function initialize() {
        $this->setSchema("jaga");
        $this->setSource("rel_instansi_wilayah");
        $this->belongsTo('id_instansi', Instansi::class, 'id');
        $this->belongsTo('id_provinsi', MasterProvinsi::class, 'provinsi_code');
        $this->belongsTo('id_kota_kabupaten', MasterKotaKabupaten::class, 'kota_kabupaten_code');
    }

    public static function isHasAgingForYear($year) {
        $total = parent::count([
            'conditions' => ':year: >= start_year and :year: <= end_year',
            'bind' => [
                'year' => $year
            ]
        ]);

        return $total > 0;
    }

    public static function findForYear($year) {
        return parent::find([
            'conditions' => ':year: >= start_year and :year: <= end_year',
            'bind' => [
                'year' => $year
            ]
        ]);
    }
}
