<?php

declare(strict_types=1);

function gm_current_year(): int
{
    return (int)date('Y');
}

/**
 * @return array<string, string>
 */
function gm_dates(): array
{
    $year = gm_current_year();

    return [
        'recent' => date('Y-m-d 10:00:00', strtotime('-1 day')),
        'current' => sprintf('%04d-01-15 09:00:00', $year),
        'previous' => sprintf('%04d-12-20 09:00:00', $year - 1),
        'notice_active' => date('Y-m-d 12:00:00', strtotime('+30 days')),
        'notice_expired' => date('Y-m-d 12:00:00', strtotime('-30 days')),
    ];
}

/**
 * @return array<string, array{name: string, email: string, active: int, admin: int, paypalname: ?string}>
 */
function gm_members(): array
{
    return [
        'admin' => [
            'name' => 'GM Admin',
            'email' => 'gm-admin@test.local',
            'active' => 1,
            'admin' => 1,
            'paypalname' => null,
        ],
        'positive' => [
            'name' => 'GM Positiv',
            'email' => 'gm-positive@test.local',
            'active' => 1,
            'admin' => 0,
            'paypalname' => null,
        ],
        'negative' => [
            'name' => 'GM Negativ',
            'email' => 'gm-negative@test.local',
            'active' => 1,
            'admin' => 0,
            'paypalname' => null,
        ],
        'zero' => [
            'name' => 'GM Nullsaldo',
            'email' => 'gm-zero@test.local',
            'active' => 1,
            'admin' => 0,
            'paypalname' => null,
        ],
        'inactive' => [
            'name' => 'GM Inaktiv',
            'email' => 'gm-inactive@test.local',
            'active' => 0,
            'admin' => 0,
            'paypalname' => null,
        ],
        'paypal' => [
            'name' => 'GM Paypal',
            'email' => 'gm-paypal@test.local',
            'active' => 1,
            'admin' => 0,
            'paypalname' => 'GM PayPal Alias',
        ],
        'empty' => [
            'name' => 'GM Ohne Buchungen',
            'email' => 'gm-empty@test.local',
            'active' => 1,
            'admin' => 0,
            'paypalname' => null,
        ],
        'heavy' => [
            'name' => 'GM Vieltrinker',
            'email' => 'gm-heavy@test.local',
            'active' => 1,
            'admin' => 0,
            'paypalname' => null,
        ],
    ];
}

/**
 * @return array<string, list<array{amount_cents: int, date_key: string}>>
 */
function gm_payments(): array
{
    return [
        'admin' => [
            ['amount_cents' => 300, 'date_key' => 'current'],
        ],
        'positive' => [
            ['amount_cents' => 2000, 'date_key' => 'current'],
            ['amount_cents' => 500, 'date_key' => 'previous'],
        ],
        'negative' => [
            ['amount_cents' => 100, 'date_key' => 'current'],
        ],
        'zero' => [
            ['amount_cents' => 200, 'date_key' => 'current'],
        ],
        'inactive' => [
            ['amount_cents' => 1000, 'date_key' => 'current'],
        ],
        'paypal' => [
            ['amount_cents' => 750, 'date_key' => 'recent'],
        ],
        'heavy' => [
            ['amount_cents' => 500, 'date_key' => 'current'],
        ],
    ];
}

/**
 * @return array<string, list<array{marks: int, unit_price_cents: int, date_key: string, entry_type: ?int}>>
 */
function gm_consumptions(): array
{
    return [
        'admin' => [
            ['marks' => 1, 'unit_price_cents' => 20, 'date_key' => 'recent', 'entry_type' => 2],
        ],
        'positive' => [
            ['marks' => 5, 'unit_price_cents' => 20, 'date_key' => 'recent', 'entry_type' => 2],
            ['marks' => 2, 'unit_price_cents' => 20, 'date_key' => 'previous', 'entry_type' => null],
        ],
        'negative' => [
            ['marks' => 10, 'unit_price_cents' => 20, 'date_key' => 'recent', 'entry_type' => null],
            ['marks' => 5, 'unit_price_cents' => 20, 'date_key' => 'previous', 'entry_type' => null],
        ],
        'zero' => [
            ['marks' => 10, 'unit_price_cents' => 20, 'date_key' => 'recent', 'entry_type' => null],
        ],
        'inactive' => [
            ['marks' => 20, 'unit_price_cents' => 20, 'date_key' => 'recent', 'entry_type' => null],
        ],
        'paypal' => [
            ['marks' => 5, 'unit_price_cents' => 20, 'date_key' => 'recent', 'entry_type' => 2],
        ],
        'heavy' => [
            ['marks' => 12, 'unit_price_cents' => 20, 'date_key' => 'recent', 'entry_type' => null],
        ],
    ];
}

/**
 * @return array<string, array{total_payments: int, total_costs: int, total_marks: int, balance: int, year_payments: int, year_costs: int, year_marks: int}>
 */
function gm_expected_summaries(): array
{
    return [
        'gm-admin@test.local' => [
            'total_payments' => 300,
            'total_costs' => 20,
            'total_marks' => 1,
            'balance' => 280,
            'year_payments' => 300,
            'year_costs' => 20,
            'year_marks' => 1,
        ],
        'gm-positive@test.local' => [
            'total_payments' => 2500,
            'total_costs' => 140,
            'total_marks' => 7,
            'balance' => 2360,
            'year_payments' => 2000,
            'year_costs' => 100,
            'year_marks' => 5,
        ],
        'gm-negative@test.local' => [
            'total_payments' => 100,
            'total_costs' => 300,
            'total_marks' => 15,
            'balance' => -200,
            'year_payments' => 100,
            'year_costs' => 200,
            'year_marks' => 10,
        ],
        'gm-zero@test.local' => [
            'total_payments' => 200,
            'total_costs' => 200,
            'total_marks' => 10,
            'balance' => 0,
            'year_payments' => 200,
            'year_costs' => 200,
            'year_marks' => 10,
        ],
        'gm-inactive@test.local' => [
            'total_payments' => 1000,
            'total_costs' => 400,
            'total_marks' => 20,
            'balance' => 600,
            'year_payments' => 1000,
            'year_costs' => 400,
            'year_marks' => 20,
        ],
        'gm-paypal@test.local' => [
            'total_payments' => 750,
            'total_costs' => 100,
            'total_marks' => 5,
            'balance' => 650,
            'year_payments' => 750,
            'year_costs' => 100,
            'year_marks' => 5,
        ],
        'gm-empty@test.local' => [
            'total_payments' => 0,
            'total_costs' => 0,
            'total_marks' => 0,
            'balance' => 0,
            'year_payments' => 0,
            'year_costs' => 0,
            'year_marks' => 0,
        ],
        'gm-heavy@test.local' => [
            'total_payments' => 500,
            'total_costs' => 240,
            'total_marks' => 12,
            'balance' => 260,
            'year_payments' => 500,
            'year_costs' => 240,
            'year_marks' => 12,
        ],
    ];
}

/**
 * @return list<string>
 */
function gm_expected_front_sheet_emails(): array
{
    return [
        'gm-heavy@test.local',
        'gm-negative@test.local',
        'gm-zero@test.local',
    ];
}

/**
 * @return list<string>
 */
function gm_expected_back_sheet_emails(): array
{
    return [
        'gm-admin@test.local',
        'gm-empty@test.local',
        'gm-paypal@test.local',
        'gm-positive@test.local',
    ];
}

function gm_cents_to_decimal(int $cents): string
{
    return number_format($cents / 100, 2, '.', '');
}

function gm_decimal_to_cents(mixed $value): int
{
    return (int)round(((float)$value) * 100);
}

