<?php

declare(strict_types=1);

namespace Kylin\Hr\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * 绩效考核模型
 *
 * 管理员工绩效考核记录，包括评分、评级、评语等。
 *
 * @property float  $total_score 总分
 * @property string $grade       评级
 * @property string $comment     评语
 * @property string $status      状态
 */
class PerformanceAppraisal extends Model
{
    protected $fillable = [
        'plan_id',
        'employee_id',
        'self_score',
        'manager_score',
        'hr_score',
        'final_score',
        'level',
        'status',
    ];

    protected function casts(): array
    {
        return [
            'self_score' => 'decimal:1',
            'manager_score' => 'decimal:1',
            'hr_score' => 'decimal:1',
            'final_score' => 'decimal:1',
            'status' => 'integer',
        ];
    }

    public function plan(): BelongsTo
    {
        return $this->belongsTo(PerformancePlan::class);
    }

    public function employee(): BelongsTo
    {
        return $this->belongsTo(Employee::class);
    }

    public function indicatorScores(): HasMany
    {
        return $this->hasMany(PerformanceIndicatorScore::class);
    }
}
