package de.sebse.fuplanner2.ui.tools.previews

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import de.sebse.fuplanner2.database.Course
import de.sebse.fuplanner2.database.Lecturer
import de.sebse.fuplanner2.utils.Faker
import de.sebse.fuplanner2.utils.getFaker

class LecturerPreviewProvider(private val faker: Faker = getFaker()) : PreviewParameterProvider<Lecturer> {
    override val values = sequence {
        yield(getItem(true))
        yield(getItem(faker.primitive.bool(.5f)))
        yieldAll(generateSequence { getItem(false) })
    }

    private fun getItem(isResponsible: Boolean): Lecturer {
        val firstName = faker.name.firstName()
        val lastName = faker.name.lastName()
        return Lecturer(
            firstName,
            lastName,
            faker.internet.email("$firstName $lastName"),
            isResponsible
        )
    }
}

class CoursePreviewProvider(private val faker: Faker = getFaker()) : PreviewParameterProvider<Course> {
    private var isSummer = false
    private var year = 21
    override val values = sequence {
        yield(getItem())
        val reduce = faker.primitive.bool(.3f)
        year = if (reduce && isSummer) year-1 else year
        isSummer = if (reduce) !isSummer else isSummer
    }

    private fun getItem(): Course {
        val diff = 1000L*60*60*24*5
        val title =
            "${faker.strings.title()} ${if (isSummer) "S" else "W"} ${if (isSummer) year else "$year/${year + 1}"}"
        return Course(
            faker.primitive.long(0, 100),
            10,
            faker.primitive.long(System.currentTimeMillis()-diff, System.currentTimeMillis()+diff),
            isSummer,
            year,
            (0..10)
                .map { faker.primitive.int(10000, 20000) }
                .map { toString() }
                .toHashSet(),
            title,
            faker.strings.courseTypes(),
            faker.strings.lorem(100, 1000),
            faker.strings.uuid(title),
            faker.primitive.int(1, 2),
            LecturerPreviewProvider(faker).values
                .take(faker.primitive.int(1, 4))
                .toList()
        )
    }
}
