<?php

namespace Portal\Mileage\Model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Project extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'lkp_project'; // because your SQL uses singular

    // Primary key
    protected $primaryKey = 'id';

    // Mass assignable fields
    protected $fillable = [
        'p_project_code',
        'p_project_description',
        'p_project_task_team',
        'p_project_director',
        'p_project_type',
        'p_total_hours',
        'p_total_days',
        'p_project_task_stage',
        'p_project_sts',
        'start_date',
        'end_date',
        'created_at',
        'updated_at',
        'updated_by',
        'deleted_at'
    ];

    // Tell Laravel which columns are dates
    protected $dates = [
        'start_date',
        'end_date',
        'created_at',
        'updated_at',
        'deleted_at'
    ];


    // Relationship with claims
    public function claims()
    {
        return $this->hasMany(Claim::class, 'project_id');
    }

    public function projectTeam()
    {
        return $this->hasMany(\Portal\Mileage\Model\ProjectTeam::class, 'fk_project_id', 'id');
    }

    // Define relationship to the user as the project manager
    public function projectManager()
    {
        return $this->belongsTo(User::class, 'project_manager_id');
    }

    // Define relationship to the user as the project director
    public function projectDirector()
    {
        return $this->belongsTo(User::class, 'project_director_id');
    }

}

