import { generatePlay } from "../../../core/tests/utils/PlayTestUtils.ts";
import { generateRandomObj } from "../../../core/tests/utils/fixtures.ts";
import { generateComponentEntity, generateInputEntity, generatePlayEntity } from "../../common/database/drizzle/entityUtils.ts";
import type {PlayNew} from "../../common/database/drizzle/drizzleTypes.ts";
import type {PlayInputNew} from "../../common/database/drizzle/drizzleTypes.ts";
import type {ComponentNew} from "../../common/database/drizzle/drizzleTypes.ts";

export const fixtureCreateComponent = (data: Partial<ComponentNew> = {}): ComponentNew => {
    return generateComponentEntity(
        {
            uid: 'test',
            mode: 'source',
            type: 'jellyfin',
            name: 'myJelly',
            ...data
        });
}

export const fixtureCreatePlay = (data: Partial<PlayNew> = {}): PlayNew => {
    const {
        play = generatePlay(),
        ...rest
    } = data;
    return generatePlayEntity(play, {seenAt: play.meta.seenAt ?? play.data.playDate, updatedAt: play.meta.seenAt ?? play.data.playDate, ...rest});
}

export const fixtureCreateInput = (data: PlayInputNew & { data?: object | false }): PlayInputNew => {
    const {
        data: inputData = generateRandomObj(),
        ...rest
    } = data;
    let realData: undefined;
    if(inputData !== false) {
        realData = inputData;
    }
    return generateInputEntity({...rest, data: realData});
}