<?php

declare(strict_types=1);

namespace App\Models;

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

class BandwidthUsage extends Model
{
    use HasFactory;

    protected $table = 'bandwidth_usage';

    protected $fillable = [
        'service_id',
        'period_start',
        'period_end',
        'bytes_in',
        'bytes_out',
        'total_bytes',
        'quota_bytes',
        'overage_bytes',
        'overage_charge',
        'source',
    ];

    protected function casts(): array
    {
        return [
            'period_start' => 'datetime',
            'period_end' => 'datetime',
            'bytes_in' => 'integer',
            'bytes_out' => 'integer',
            'total_bytes' => 'integer',
            'quota_bytes' => 'integer',
            'overage_bytes' => 'integer',
            'overage_charge' => 'decimal:2',
        ];
    }

    public function service(): BelongsTo
    {
        return $this->belongsTo(Service::class);
    }
}
