<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\HourRegistration\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Maestro\Core\Modules\Customers\Models\Customer;
use Maestro\Core\Support\AuthUserResolver;

class HourProject extends Model
{
    protected $table = 'hour_projects';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'customer_id',
        'project_lead_id',
        'is_active',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
        ];
    }

    /**
     * @return BelongsTo<Customer, HourProject>
     */
    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

    /**
     * @return BelongsTo<Model, HourProject>
     */
    public function projectLead(): BelongsTo
    {
        return $this->belongsTo(AuthUserResolver::eloquentModelClass(), 'project_lead_id');
    }

    /**
     * @return HasMany<HourTask, HourProject>
     */
    public function tasks(): HasMany
    {
        return $this->hasMany(HourTask::class, 'hour_project_id');
    }
}
