// File generated from our OpenAPI spec by Stainless.

package com.openai.models.finetuning.jobs

import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.openai.core.JsonValue
import com.openai.core.jsonMapper
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class JobListPageResponseTest {

    @Test
    fun create() {
        val jobListPageResponse =
            JobListPageResponse.builder()
                .addData(
                    FineTuningJob.builder()
                        .id("id")
                        .createdAt(0L)
                        .error(
                            FineTuningJob.Error.builder()
                                .code("code")
                                .message("message")
                                .param("param")
                                .build()
                        )
                        .fineTunedModel("fine_tuned_model")
                        .finishedAt(0L)
                        .hyperparameters(
                            FineTuningJob.Hyperparameters.builder()
                                .batchSizeAuto()
                                .learningRateMultiplierAuto()
                                .nEpochsAuto()
                                .build()
                        )
                        .model("model")
                        .organizationId("organization_id")
                        .addResultFile("file-abc123")
                        .seed(0L)
                        .status(FineTuningJob.Status.VALIDATING_FILES)
                        .trainedTokens(0L)
                        .trainingFile("training_file")
                        .validationFile("validation_file")
                        .estimatedFinish(0L)
                        .addIntegration(
                            FineTuningJobWandbIntegrationObject.builder()
                                .wandb(
                                    FineTuningJobWandbIntegration.builder()
                                        .project("my-wandb-project")
                                        .entity("entity")
                                        .name("name")
                                        .addTag("custom-tag")
                                        .build()
                                )
                                .build()
                        )
                        .metadata(
                            FineTuningJob.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .method(
                            FineTuningJob.Method.builder()
                                .dpo(
                                    FineTuningJob.Method.Dpo.builder()
                                        .hyperparameters(
                                            FineTuningJob.Method.Dpo.Hyperparameters.builder()
                                                .batchSizeAuto()
                                                .betaAuto()
                                                .learningRateMultiplierAuto()
                                                .nEpochsAuto()
                                                .build()
                                        )
                                        .build()
                                )
                                .supervised(
                                    FineTuningJob.Method.Supervised.builder()
                                        .hyperparameters(
                                            FineTuningJob.Method.Supervised.Hyperparameters
                                                .builder()
                                                .batchSizeAuto()
                                                .learningRateMultiplierAuto()
                                                .nEpochsAuto()
                                                .build()
                                        )
                                        .build()
                                )
                                .type(FineTuningJob.Method.Type.SUPERVISED)
                                .build()
                        )
                        .build()
                )
                .hasMore(true)
                .build()

        assertThat(jobListPageResponse.data())
            .containsExactly(
                FineTuningJob.builder()
                    .id("id")
                    .createdAt(0L)
                    .error(
                        FineTuningJob.Error.builder()
                            .code("code")
                            .message("message")
                            .param("param")
                            .build()
                    )
                    .fineTunedModel("fine_tuned_model")
                    .finishedAt(0L)
                    .hyperparameters(
                        FineTuningJob.Hyperparameters.builder()
                            .batchSizeAuto()
                            .learningRateMultiplierAuto()
                            .nEpochsAuto()
                            .build()
                    )
                    .model("model")
                    .organizationId("organization_id")
                    .addResultFile("file-abc123")
                    .seed(0L)
                    .status(FineTuningJob.Status.VALIDATING_FILES)
                    .trainedTokens(0L)
                    .trainingFile("training_file")
                    .validationFile("validation_file")
                    .estimatedFinish(0L)
                    .addIntegration(
                        FineTuningJobWandbIntegrationObject.builder()
                            .wandb(
                                FineTuningJobWandbIntegration.builder()
                                    .project("my-wandb-project")
                                    .entity("entity")
                                    .name("name")
                                    .addTag("custom-tag")
                                    .build()
                            )
                            .build()
                    )
                    .metadata(
                        FineTuningJob.Metadata.builder()
                            .putAdditionalProperty("foo", JsonValue.from("string"))
                            .build()
                    )
                    .method(
                        FineTuningJob.Method.builder()
                            .dpo(
                                FineTuningJob.Method.Dpo.builder()
                                    .hyperparameters(
                                        FineTuningJob.Method.Dpo.Hyperparameters.builder()
                                            .batchSizeAuto()
                                            .betaAuto()
                                            .learningRateMultiplierAuto()
                                            .nEpochsAuto()
                                            .build()
                                    )
                                    .build()
                            )
                            .supervised(
                                FineTuningJob.Method.Supervised.builder()
                                    .hyperparameters(
                                        FineTuningJob.Method.Supervised.Hyperparameters.builder()
                                            .batchSizeAuto()
                                            .learningRateMultiplierAuto()
                                            .nEpochsAuto()
                                            .build()
                                    )
                                    .build()
                            )
                            .type(FineTuningJob.Method.Type.SUPERVISED)
                            .build()
                    )
                    .build()
            )
        assertThat(jobListPageResponse.hasMore()).isEqualTo(true)
    }

    @Test
    fun roundtrip() {
        val jsonMapper = jsonMapper()
        val jobListPageResponse =
            JobListPageResponse.builder()
                .addData(
                    FineTuningJob.builder()
                        .id("id")
                        .createdAt(0L)
                        .error(
                            FineTuningJob.Error.builder()
                                .code("code")
                                .message("message")
                                .param("param")
                                .build()
                        )
                        .fineTunedModel("fine_tuned_model")
                        .finishedAt(0L)
                        .hyperparameters(
                            FineTuningJob.Hyperparameters.builder()
                                .batchSizeAuto()
                                .learningRateMultiplierAuto()
                                .nEpochsAuto()
                                .build()
                        )
                        .model("model")
                        .organizationId("organization_id")
                        .addResultFile("file-abc123")
                        .seed(0L)
                        .status(FineTuningJob.Status.VALIDATING_FILES)
                        .trainedTokens(0L)
                        .trainingFile("training_file")
                        .validationFile("validation_file")
                        .estimatedFinish(0L)
                        .addIntegration(
                            FineTuningJobWandbIntegrationObject.builder()
                                .wandb(
                                    FineTuningJobWandbIntegration.builder()
                                        .project("my-wandb-project")
                                        .entity("entity")
                                        .name("name")
                                        .addTag("custom-tag")
                                        .build()
                                )
                                .build()
                        )
                        .metadata(
                            FineTuningJob.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .method(
                            FineTuningJob.Method.builder()
                                .dpo(
                                    FineTuningJob.Method.Dpo.builder()
                                        .hyperparameters(
                                            FineTuningJob.Method.Dpo.Hyperparameters.builder()
                                                .batchSizeAuto()
                                                .betaAuto()
                                                .learningRateMultiplierAuto()
                                                .nEpochsAuto()
                                                .build()
                                        )
                                        .build()
                                )
                                .supervised(
                                    FineTuningJob.Method.Supervised.builder()
                                        .hyperparameters(
                                            FineTuningJob.Method.Supervised.Hyperparameters
                                                .builder()
                                                .batchSizeAuto()
                                                .learningRateMultiplierAuto()
                                                .nEpochsAuto()
                                                .build()
                                        )
                                        .build()
                                )
                                .type(FineTuningJob.Method.Type.SUPERVISED)
                                .build()
                        )
                        .build()
                )
                .hasMore(true)
                .build()

        val roundtrippedJobListPageResponse =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(jobListPageResponse),
                jacksonTypeRef<JobListPageResponse>(),
            )

        assertThat(roundtrippedJobListPageResponse).isEqualTo(jobListPageResponse)
    }
}
