package com.nisemoe.nise.rss

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import kotlinx.serialization.Serializable

@JacksonXmlRootElement(localName = "rss")
@Serializable
data class RssFeed(
    @JacksonXmlProperty(isAttribute = true)
    val version: String = "2.0",
    val channel: Channel,

    @JacksonXmlProperty(localName = "xmlns:atom", isAttribute = true)
    val atomLink: String = "http://www.w3.org/2005/Atom"
)

@Serializable
data class Channel(
    val title: String,
    val link: String,
    val description: String,
    @JacksonXmlProperty(localName = "lastBuildDate")
    val lastBuildDate: String,
    @JacksonXmlElementWrapper(useWrapping = false)
    val item: List<Item>,
    @JacksonXmlProperty(localName = "atom:link")
    val atomLink: AtomLink
)

@Serializable
data class AtomLink(
    @JacksonXmlProperty(localName = "href", isAttribute = true)
    val href: String,
    @JacksonXmlProperty(localName = "rel", isAttribute = true)
    val rel: String = "self",
    @JacksonXmlProperty(localName = "type", isAttribute = true)
    val type: String = "application/rss+xml"
)

@Serializable
data class Item(
    val title: String,
    val guid: String,
    val link: String,
    val description: String,
    @JacksonXmlProperty(localName = "pubDate")
    val pubDate: String
)