<?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 string $name      指标名称
 * @property float  $weight    权重
 * @property float  $target    目标值
 * @property string $scale     评分标准
 */
class PerformanceIndicator extends Model
{
    protected $fillable = [
        'plan_id',
        'name',
        'weight',
        'target_value',
        'scoring_rule',
        'sort',
    ];

    protected function casts(): array
    {
        return [
            'weight' => 'decimal:2',
            'sort' => 'integer',
        ];
    }

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

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