<?php
namespace App\Models;
use CodeIgniter\Model;

class JobAssigneeModel extends Model
{
    protected $table         = 'job_assignees';
    protected $primaryKey    = 'id';
    protected $allowedFields = ['job_id','user_id','is_lead','assigned_at','assigned_by',
        'created_at', 'updated_at', 'deleted_at'];

    public function userIdsForJob(int $jobId): array
    {
        return array_column($this->where('job_id', $jobId)->findAll(), 'user_id');
    }

    public function forJob(int $jobId): array
    {
        return $this->select('job_assignees.*, users.first_name, users.last_name, users.color')
                    ->join('users', 'users.id = job_assignees.user_id')
                    ->where('job_id', $jobId)->findAll();
    }
}
