<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class AttendancePeriod extends Model
{
    protected $table = 'attendance_periods';

    protected $fillable = [
        'period_month',
        'cutoff_date',
        'transferred_at',
        'total_records',
    ];

    protected $casts = [
        'period_month' => 'date',
        'cutoff_date' => 'date',
        'transferred_at' => 'datetime',
    ];

    /**
     * Check if a period has been transferred
     */
    public static function isTransferred(string $periodMonth): bool
    {
        return self::where('period_month', $periodMonth)->exists();
    }

    /**
     * Get the latest transferred period
     */
    public static function getLatestTransferred(): ?self
    {
        return self::orderBy('period_month', 'desc')->first();
    }
}
