<?php

namespace App\Services\Invoices;

use App\Models\Configuration;

class InvoiceConfigService
{
    public function getSchoolYear(): string
    {
        return (string) (Configuration::getConfig('school_year') ?? date('Y'));
    }

    public function getSemester(): string
    {
        return (string) (Configuration::getConfig('semester') ?? 'Fall');
    }

    public function getDueDate(): ?string
    {
        $value = Configuration::getConfig('due_date');
        return $value ? (string) $value : null;
    }

    public function getGradeFee(): int
    {
        return (int) (Configuration::getConfig('grade_fee') ?? 9);
    }

    public function getFirstStudentFee(): float
    {
        return (float) (Configuration::getConfig('first_student_fee') ?? 350);
    }

    public function getSecondStudentFee(): float
    {
        return (float) (Configuration::getConfig('second_student_fee') ?? 200);
    }

    public function getYouthFee(): float
    {
        return (float) (Configuration::getConfig('youth_fee') ?? 180);
    }

    public function getRefundDeadline(): ?string
    {
        $value = Configuration::getConfig('refund_deadline');
        if (!$value) {
            return null;
        }

        try {
            return date('Y-m-d', strtotime((string) $value));
        } catch (\Throwable $e) {
            return null;
        }
    }

    public function getTimezone(): string
    {
        return (string) (config('School')->attendance['timezone'] ?? user_timezone());
    }
}
