<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    protected $fillable = ['client_request_id', 'client_id', 'designer_id', 'title', 'details', 'notes', 'priority', 'deadline', 'status', 'usage_counted_at'];

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

    public function client()
    {
        return $this->belongsTo(User::class, 'client_id');
    }

    public function designer()
    {
        return $this->belongsTo(User::class, 'designer_id');
    }

    public function request()
    {
        return $this->belongsTo(ClientRequest::class, 'client_request_id');
    }

    public function files()
    {
        return $this->hasMany(TaskFile::class);
    }

    public function histories()
    {
        return $this->hasMany(TaskHistory::class);
    }
}
