<?php

namespace Modules\Country\Http\Controllers;

use App\Functions\ResponseHelper;
use App\Http\Controllers\BasicController;
use Modules\Country\Entities\Country;
use Modules\Country\Entities\Region;

class APIController extends BasicController
{
    public function countries()
    {
        return ResponseHelper::make(Country::select('id', 'title_'.lang().' As title', 'phone_code', 'length', 'image')->Active()->orderByRaw("FIELD(id, 1,2,3,4,5,6,7,8,9,10)")->get()->each(function ($item, $key) {
            $item->image = asset($item->image);
        }));
    }

    public function regions()
    {
        return ResponseHelper::make(Region::select('id', 'title_'.lang().' As title')->where('country_id', request('country_id') ?? 2)->Active()->get());
    }
}
