<?php

namespace App\Models\Pertanian;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Wilayah\DesaKelurahan;
use App\Models\Pertanian\Tanaman;
use App\Models\Profile;
use App\Enums\StatusLahan;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Lahan extends Model
{
    use SoftDeletes;

    protected $table = 'map_lahan';

    protected $fillable = [
        'nama',
        'status_kepemilikan',
        'profile_id',
        'keluarga_pengelola_id',
        'adat_pemilik_id',
        'desa_kelurahan_id',
        'path',
        'luas_lahan',
        'created_by',
        'updated_by',
        'deleted_by',
    ];

    protected $casts = [
        'status_kepemilikan' => StatusLahan::class,
        'path' => 'array',
    ];

    public function profile(): BelongsTo
    {
        return $this->belongsTo(Profile::class, 'profile_id');
    }

    public function desaKelurahan(): BelongsTo
    {
        return $this->belongsTo(DesaKelurahan::class, 'desa_kelurahan_id');
    }

    public function tanaman(): HasMany
    {
        return $this->hasMany(Tanaman::class, 'lahan_id');
    }
}
