<?php

namespace App\Models;

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

class BatchSplitSession extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'source_batch_id',
        'date',
        'fish_count_theoretical',
        'fish_count_counted',
        'fish_missing',
        'fish_moved_total',
        'fish_remaining_source',
        'biomass_moved_total_kg',
        'avg_weight_reference_g',
        'notes',
        'revision_count',
        'adjustment_reason',
        'last_adjusted_at',
        'last_adjusted_by',
    ];

    protected $casts = [
        'date' => 'date',
        'last_adjusted_at' => 'datetime',
    ];

    public function sourceBatch(): BelongsTo
    {
        return $this->belongsTo(Batch::class, 'source_batch_id');
    }

    public function events(): HasMany
    {
        return $this->hasMany(BatchSplitEvent::class, 'batch_split_session_id');
    }

    public function lastAdjustedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'last_adjusted_by');
    }
}
