<?php

namespace App\Models;

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

class TeacherLeave extends Model
{
    use HasFactory;

    protected $table = 'teacher_leaves';
    
    protected $fillable = [
        'teacher_id',
        'leave_type',
        'start_date',
        'end_date',
        'total_days',
        'reason',
        'applied_date',
        'approved_by',
        'approval_date',
        'status', // pending, approved, rejected
        'remarks'
    ];

    protected $casts = [
        'start_date' => 'date',
        'end_date' => 'date',
        'applied_date' => 'date',
        'approval_date' => 'date',
        'total_days' => 'integer'
    ];

    public function teacher()
    {
        return $this->belongsTo(Teacher::class);
    }

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

    // Leave types
    public static function getLeaveTypes()
    {
        return [
            'casual' => 'ক্যাজুয়াল ছুটি',
            'sick' => 'অসুস্থতাজনিত ছুটি',
            'earned' => 'অর্জিত ছুটি',
            'maternity' => 'মাতৃত্বকালীন ছুটি',
            'paternity' => 'পিতৃত্বকালীন ছুটি',
            'study' => 'অধ্যয়ন ছুটি',
            'without_pay' => 'বিনা বেতনে ছুটি',
            'other' => 'অন্যান্য'
        ];
    }

    // Calculate total days
    public function calculateTotalDays()
    {
        if ($this->start_date && $this->end_date) {
            return $this->start_date->diffInDays($this->end_date) + 1;
        }
        return 0;
    }
}