<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class WorkExperience extends Model
{
    use HasFactory;
    protected $fillable = [
        'user_id',
        'company',
        'type_company',
        'department',
        'title_position',
        'direction',
        'phone',
        'date_entry',
        'date_retirement',
        'responsibilities',
        'is_currently_working_here',
        'document_upload'
    ];

    public function getTypeCompanyNameAttribute()
    {
        $type_company = [
            '1' => 'Público',
            '2' => 'Privado'
        ];
        return $type_company[$this->type_company];
    }
    public function getDurationAttribute()
    {
        $date_entry = new Carbon($this->date_entry);
        $date_retirement = new Carbon($this->date_retirement);
        $duration = $date_entry->diffInMonths($date_retirement);
        return $duration.' meses';
    }

    public function countries(){
        return $this->belongsTo(Country::class);
    }
}
