<?php

namespace App\Models;

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

class Task extends Model
{
    use HasFactory;

    protected $fillable = [
        'assigned_to',
        'assigned_by',
        'title',
        'description',
        'deadline',
        'priority',
        'point_value',
        'expected_output',
        'completion_percentage',
        'admin_override_percentage',
        'status',
        'feedback',
    ];

    protected function casts(): array
    {
        return [
            'deadline' => 'date',
        ];
    }

    public function assignee(): BelongsTo
    {
        return $this->belongsTo(User::class, 'assigned_to');
    }

    public function assigner(): BelongsTo
    {
        return $this->belongsTo(User::class, 'assigned_by');
    }

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

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

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