<?php

if (!function_exists('getConstant')) {
    function getConstant($key = null, $default = null) {
        return config('const.' . $key, $default);
    }
}

if (!function_exists('configProject')) {
    function configProject($key = null, $default = null) {
        return config('project.' . $key, $default);
    }
}

if (!function_exists('jsonEncodeJp')) {
    function jsonEncodeJp($value)
    {
        return json_encode($value, JSON_UNESCAPED_UNICODE);
    }
}

if (!function_exists('getBukkenNameWithGouchi')) {
    function getBukkenNameWithGouchi(?string $name = null, ?string $nameGouchi = null): ?string
    {
        if (!auth()->user()->company_id == 3) {
            return $name;
        }

        if (!empty($nameGouchi)) {
            if (strpos($name, '新築')) {
                return str_replace('新築戸建', $nameGouchi . '号地 新築戸建', $name);
            }
            if (strpos($name, '中古')) {
                return str_replace('中古戸建', $nameGouchi . '号地 中古戸建', $name);
            }
            if (strpos($name, '土地')) {
                return str_replace('土地', $nameGouchi . '号地 土地', $name);
            }

            return $name . ' ' . $nameGouchi . '号地';
        }

        return $name;
    }
}
