<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class PointCalculation extends Model
{
	const TYPE_TRIAL = 1;
	const TYPE_OFFICIAL = 2;
	
	protected $fillable = [
		'employee_id',
		'calculation_date',
		'tenure_points', //thâm niên
		'level_points', //cấp bậc
		'position_points', //chức vụ
		'tenure_transition_points', //điểm chuyển tiếp thâm niên
		'level_transition_points', //điểm chuyển tiếp cấp bậc
		'position_transition_points', //điểm chuyển tiếp vị trí
		'transition_points', //tổng điểm chuyển tiếp
		'total_points', //tổng điểm
		'calculation_type'
	];
	
	protected $casts = [
		'calculation_date'  => 'date',
		'tenure_points'     => 'decimal:2',
		'position_points'   => 'decimal:2',
		'education_points'  => 'decimal:2',
		'transition_points' => 'decimal:2',
		'total_points'      => 'decimal:2'
	];
	
	public function employee()
	{
		return $this->belongsTo(Employee::class)->with('department')->select('*');
	}
	
	public function severancePayment()
	{
		return $this->hasOne(SeverancePayment::class);
	}
	
	public function scopeTrial($query)
	{
		return $query->where('calculation_type', self::TYPE_TRIAL);
	}
	
	public function scopeOfficial($query)
	{
		return $query->where('calculation_type', self::TYPE_OFFICIAL);
	}
}