import { expect, test } from "vitest";
import { parseForm } from "@/shared/forms/validation";
import { buildTaskPayload, defaultAppJumpParam } from "./hooks/useDailyTasksPage.js";
import { dailyTaskFormSchema } from "./schema";

test("daily task payload stores public app jump params for explore game", () => {
    const form = parseForm(dailyTaskFormSchema, {
        actionType: "explore_game",
        appJumpParam: '{"type":"explore_game","game_code":"game_dice"}',
        description: "",
        effectiveFrom: "",
        effectiveTo: "",
        iconUrl: "https://media.haiyihy.com/admin/images/task-game.png",
        metricType: "game_dice_play_count",
        rewardCoinAmount: "20",
        sortOrder: "3",
        status: "active",
        targetUnit: "count",
        targetValue: "1",
        taskType: "daily",
        title: "玩 Dice Battle 1 局",
    });

    const payload = buildTaskPayload(form);

    expect(payload.category).toBe("game_dice_play_count");
    expect(payload.audience_type).toBe("all");
    expect(payload.dimension_filter_json).toBe("{}");
    expect(payload.icon_key).toBe("");
    expect(payload.icon_url).toBe("https://media.haiyihy.com/admin/images/task-game.png");
    expect(payload.action_type).toBe("explore_game");
    expect(payload.action_param).toBe("game_dice");
    expect(payload.action_payload_json).toBe('{"type":"explore_game","game_code":"game_dice"}');
});

test("daily task action type selection provides public app jump template", () => {
    expect(defaultAppJumpParam()).toBe('{"type":"wallet"}');
});
