<?php

namespace Modules\PMS\Models;

use App\Traits\CreatedUpdatedBy;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Modules\Employee\Models\Employee;

class Task extends Model
{
    use StatusTrait, CreatedUpdatedBy;

    protected $table = 'tbl_tasks';
    protected $guarded = [];
    protected $appends = ['status_name', 'priority_status'];

    const CATEGORY = [
        10 => 'Vue',
        11 => 'Laravel',
    ];

    const PRIORITY = [
        10 => 'High',
        11 => 'Meduim',
        12 => 'Low',
    ];

    protected function priorityStatus(): Attribute
    {
        return Attribute::make(
            get: function (mixed $value, array $attributes) {
                switch ($attributes['priority']) {
                    case '10':
                        return '<span class="badge bg-danger">' . self::PRIORITY[$attributes['priority']] . '</span>';
                        break;
                    case '11':
                        return '<span class="badge bg-info">' . self::PRIORITY[$attributes['priority']] . '</span>';
                        break;
                    case '12':
                        return '<span class="badge bg-primary">' . self::PRIORITY[$attributes['priority']] . '</span>';
                        break;
                    default:
                        # code...
                        break;
                }
            },
            set: fn($value) => $value,
        );
    }

    public function project()
    {
        return $this->belongsTo(Project::class, 'project_id');
    }

    public function assigned()
    {
        return $this->belongsTo(Employee::class, 'assigned_id');
    }

}