package com.nisemoe.nise.rss

import com.nisemoe.nise.scheduler.GlobalCache
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
import java.time.LocalDateTime
import java.time.OffsetDateTime

@RestController
class RssFeedController(
    private val globalCache: GlobalCache
) {

    data class IntermeriaryFeedItem(
        val title: String,
        val guid: String,
        val link: String,
        val description: String,
        val pubDate: OffsetDateTime
    )

    @GetMapping(path = ["rss", "rss.xml"], produces = [MediaType.APPLICATION_RSS_XML_VALUE])
    fun getRssFeed(): ResponseEntity<RssFeed> {
        val feed = this.globalCache.rssFeed
            ?: return ResponseEntity.status(503).build()

        return ResponseEntity.ok(feed)
    }

}