<?php

namespace App\Models;

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

class HistoryContractsUser extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'contract_id',
        'company_id',
        'job_position',
        'salary_type',
        'base_salary',
        'performance_factor',
        'salary',
        'payment_method',
        'content_contract',
        'start_date',
        'end_date',
        'start_date_work',
        'end_date_work',
        'place_hired',
        'place_work',
        'work_day',
        'energy_cost',
        'maintenance_technology_resources_cost',
        'phone_cost',
        'others_cost',
        'no_salary_cost',
        'status',
        'signature_employee',
        'signature_company',
        'signature_full_name',
        'signature_position',
        'signature_document_type',
        'signature_document_number',
        'signature_date',
        'active_signature_employee',
        'signature_employee_code',
        'created_by',
        'ref_reason_termination',
        'reason_termination',
        'date_termination',
        'user_termination',
        'created_at',
        'updated_at',
    ];

    public function getDurationAttribute()
    {
        return Carbon::parse($this->start_date)->diffInMonths(Carbon::parse($this->end_date));
    }

    public function getStartDateEsAttribute($value)
    {
        return Carbon::parse($this->start_date)->day . ' de ' . Carbon::parse($this->start_date)->monthName . ' de ' . Carbon::parse($this->start_date)->year;
    }

    public function getEndDateEsAttribute($value)
    {
        return Carbon::parse($this->end_date)->day . ' de ' . Carbon::parse($this->end_date)->monthName . ' de ' . Carbon::parse($this->end_date)->year;
    }
}
