<?php

namespace App\Services\Grading\Snapshots;

use App\Models\SemesterScore;
use App\Models\SemesterScoreSnapshot;

class SemesterScoreSnapshotService
{
    public function createForScore(SemesterScore $score, array $input, array $calculation, ?int $actorId = null): SemesterScoreSnapshot
    {
        return SemesterScoreSnapshot::query()->create([
            'student_id' => $score->student_id,
            'school_id' => $score->school_id,
            'class_section_id' => $score->class_section_id,
            'semester' => $score->semester,
            'school_year' => $score->school_year,
            'grading_profile_id' => null,
            'grading_profile_version' => $score->calculation_policy_version ?: 'strong_v1',
            'calculation_mode' => $score->calculation_mode ?: 'strong',
            'calculation_policy_version' => $score->calculation_policy_version ?: 'strong_v1',
            'input_json' => $input,
            'calculation_json' => $calculation,
            'semester_score' => $score->semester_score,
            'calculated_by' => $actorId,
            'calculated_at' => now(),
        ]);
    }
}
