<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Country extends Model
{
    protected $fillable = [
        'code',
        'name',
        'continent',
    ];

    public function regions(): HasMany
    {
        return $this->hasMany(Region::class);
    }

    function sortedRegions(): array
    {
        return $this
            ->regions()
            ->orderBy('name')
            ->get()
            ->toArray();
    }
}
