<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class StaffInvoice extends Model
{
    protected $fillable = [
        'invoice_number', 'user_id', 'period_start', 'period_end',
        'total_hours', 'hourly_rate', 'total_amount', 'status',
        'approved_by', 'approved_at', 'approval_notes', 'notes',
    ];

    protected $casts = [
        'period_start' => 'date',
        'period_end'   => 'date',
        'approved_at'  => 'datetime',
    ];

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

    public function getStatusBadgeAttribute(): string
    {
        return match($this->status) {
            'approved' => 'bg-green-100 text-green-800',
            'rejected' => 'bg-red-100 text-red-800',
            'paid'     => 'bg-blue-100 text-blue-800',
            default    => 'bg-yellow-100 text-yellow-800',
        };
    }
}
