<?php

namespace App\Models;

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

class JobPost extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'employer_id',
        'title',
        'category_id',
        'workers_needed',
        'job_type',
        'location',
        'salary',
        'start_date',
        'description',
        'requirements',
        'status',
    ];

    protected $casts = [
        'start_date' => 'date',
        'salary' => 'decimal:2',
        'workers_needed' => 'integer',
    ];

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

    public function category()
    {
        return $this->belongsTo(WorkerCategory::class, 'category_id');
    }

    public function applications()
    {
        return $this->hasMany(JobApplication::class, 'job_id');
    }
}
