<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use OwenIt\Auditing\Contracts\Auditable;

class InvestmentOpportunity extends Model implements Auditable
{
    use HasFactory, SoftDeletes;
    use \OwenIt\Auditing\Auditable;

    protected $fillable = [
        'code', 'title_pt', 'title_en', 'description_pt', 'description_en',
        'sector', 'status', 'project_status', 'is_featured', 'is_special_economic_zone', 'tags',
        'province_id', 'district_id', 'address', 'latitude', 'longitude',
        'min_investment', 'max_investment', 'expected_return_rate',
        'return_period_years', 'total_jobs', 'images', 'documents',
        'created_by', 'updated_by', 'published_at', 'closed_at',
    ];

    protected function casts(): array
    {
        return [
            'tags' => 'array',
            'images' => 'array',
            'documents' => 'array',
            'is_featured' => 'boolean',
            'is_special_economic_zone' => 'boolean',
            'published_at' => 'datetime',
            'closed_at' => 'datetime',
            'min_investment' => 'decimal:2',
            'max_investment' => 'decimal:2',
        ];
    }

    public function province(): BelongsTo { return $this->belongsTo(Province::class); }
    public function district(): BelongsTo { return $this->belongsTo(District::class); }
    public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); }
    public function expressionsOfInterest(): HasMany { return $this->hasMany(ExpressionOfInterest::class, 'opportunity_id'); }
}
