<commit_before><?php namespace Syscover\Pulsar\Models;

use Illuminate\Support\Facades\Validator;
use Syscover\Pulsar\Traits\TraitModel;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Mappable;

/**
 * Class TerritorialArea2
 *
 * Model with properties
 * <br><b>[id, country, territorial_area_1, name]</b>
 *
 * @package     Syscover\Pulsar\Models
 */

class TerritorialArea2 extends Model
{
    use TraitModel;
    use Eloquence, Mappable;

    protected $table        = '001_004_territorial_area_2';
    protected $primaryKey   = 'id_004';
    protected $suffix       = '004';
    public $timestamps      = false;
    protected $fillable     = ['id_004', 'country_004', 'territorial_area_1_004', 'name_004'];
    protected $maps         = [];
    protected $relationMaps = [
        'terrirorial_area_1'   => \Syscover\Pulsar\Models\TerritorialArea1::class
    ];
    private static $rules   = [
        'id'                => 'required|between:1,10|unique:001_004_territorial_area_2,id_004',
        'name'              => 'required|between:2,50',
        'territorialArea1'  => 'not_in:null'
    ];

    public static function validate($data, $specialRules = [])
    {
        if(isset($specialRules['idRule']) && $specialRules['idRule'])   static::$rules['id'] = 'required|between:1,10';

        return Validator::make($data, static::$rules);
    }

    public function scopeBuilder($query)
    {
        return $query->join('001_003_territorial_area_1', '001_004_territorial_area_2.territorial_area_1_004', '=', '001_003_territorial_area_1.id_003');
    }

    public function getTerritorialAreas3()
    {
         return $this->hasMany('Syscover\Pulsar\Models\TerritorialArea3', 'territorial_area_2_005');
    }
     
    public static function addToGetIndexRecords($parameters)
    {
        $query = TerritorialArea2::builder();

        if(isset($parameters['country'])) $query->where('country_003', $parameters['country']);

        return $query;
    }

    public static function customCount($parameters)
    {
        $query = TerritorialArea2::query();

        if(isset($parameters['country'])) $query->where('country_004', $parameters['country']);

        return $query;
    }

    public static function getTerritorialAreas2FromTerritorialArea1($terrirotialArea1)
    {<commit_msg>add country to ta2<commit_after><?php namespace Syscover\Pulsar\Models;

use Illuminate\Support\Facades\Validator;
use Syscover\Pulsar\Traits\TraitModel;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Mappable;

/**
 * Class TerritorialArea2
 *
 * Model with properties
 * <br><b>[id, country, territorial_area_1, name]</b>
 *
 * @package     Syscover\Pulsar\Models
 */

class TerritorialArea2 extends Model
{
    use TraitModel;
    use Eloquence, Mappable;

    protected $table        = '001_004_territorial_area_2';
    protected $primaryKey   = 'id_004';
    protected $suffix       = '004';
    public $timestamps      = false;
    protected $fillable     = ['id_004', 'country_004', 'territorial_area_1_004', 'name_004'];
    protected $maps         = [];
    protected $relationMaps = [
        'terrirorial_area_1'   => \Syscover\Pulsar\Models\TerritorialArea1::class
    ];
    private static $rules   = [
        'id'                => 'required|between:1,10|unique:001_004_territorial_area_2,id_004',
        'name'              => 'required|between:2,50',
        'territorialArea1'  => 'not_in:null'
    ];

    public static function validate($data, $specialRules = [])
    {
        if(isset($specialRules['idRule']) && $specialRules['idRule'])   static::$rules['id'] = 'required|between:1,10';

        return Validator::make($data, static::$rules);
    }

    public function scopeBuilder($query)
    {
        return $query->join('001_002_country', '001_004_territorial_area_2.country_004', '=', '001_002_country.id_002')
            ->join('001_003_territorial_area_1', '001_004_territorial_area_2.territorial_area_1_004', '=', '001_003_territorial_area_1.id_003');
    }

    public function getTerritorialAreas3()
    {
         return $this->hasMany('Syscover\Pulsar\Models\TerritorialArea3', 'territorial_area_2_005');
    }
     
    public static function addToGetIndexRecords($parameters)
    {
        $query = TerritorialArea2::builder();

        if(isset($parameters['country'])) $query->where('country_003', $parameters['country']);

        return $query;
    }

    public static function customCount($parameters)
    {
        $query = TerritorialArea2::query();

        if(isset($parameters['country'])) $query->where('country_004', $parameters['country']);

        return $query;
    }

    public static function getTerritorialAreas2FromTerritorialArea1($terrirotialArea1)
    {
{'fraction_non_alphanumeric': 0.1359017781541067, 'fraction_numerical': 0.04614733276883996, 'mean_word_length': 3.4871794871794872, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1452952', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1520, 'n_words': 236}