<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MstPropertyType extends Model
{
    public const MANSION_ID = 6;
    public const MANSION_ID2 = 7;
    public const LAND_ID = 1;
    public const LAND_ID2 = 2;
    public const LAND_ID3 = 3;
    public const HOUSE_ID = 4; //property_sub = 1 => (new House) property_sub = 2 => (old house)
    public const HOUSE_ID2 = 5; //property_sub = 1 => (new House) property_sub = 2 => (old house)
    public const ROOM_ID = null; //has mansion_id not null
    public const LOT_ID = 99;
    public const NEW = 1;
    public const OLD = 2;

    //
    public static function getData($code='')
    {
        if($code == ''){
            $types = MstPropertyType::get();

            $arrResult = array();
            foreach($types as $type){
                 $arrResult[] = ['code' => $type->code, 'name' => $type->name];
            }
            return $arrResult;
        } else {
            $types = MstPropertyType::where('code', '=', $code)->get();

            $arrResult = array();
            foreach($types as $type){
                 $arrResult[] = ['code' => $type->code, 'name' => $type->name];
            }
            return $arrResult;
        }
    }

    public static function getDataByParentId($parentCode='')
    {
        if($parentCode != ''){
            $types = MstPropertyType::where('parent_code', '=', $parentCode)->get();

            $arrResult = array();
            foreach($types as $type){
                 $arrResult[] = ['code' => $type->code, 'name' => $type->name];
            }
            return $arrResult;
        }
    }
}
