<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ProjectMonthPlan extends Model
{
    use HasUuids;

    protected $table = 'project_month_plans';

    protected $fillable = [
        'project_id',
        'month',
        'planned_hours',
    ];

    protected $casts = [
        'month' => 'date:Y-m-01',
        'planned_hours' => 'decimal:2',
    ];

    /**
     * Get the project this plan belongs to.
     */
    public function project(): BelongsTo
    {
        return $this->belongsTo(Project::class);
    }

    /**
     * Check if this plan cell is blank (unset).
     */
    public function isBlank(): bool
    {
        return $this->planned_hours === null;
    }

    /**
     * Get planned hours or 0 for variance calculations.
     * Blank plan is treated as 0 for allocation variance.
     */
    public function getPlannedHoursForVariance(): float
    {
        return (float) ($this->planned_hours ?? 0);
    }
}
