//
//  MPPositive_JsonCharts.swift
//  relax.offline.mp3.music
//
//  Created by Mr.Zhou on 2024/7/2.
//

import Foundation
///排行榜结构体
struct JsonCharts: Codable {
    let contents:Contents?
    enum CodingKeys: String, CodingKey {
       case contents = "contents"
    }
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        contents = try values.decodeIfPresent(Contents.self, forKey: .contents)
    }
    struct Contents: Codable {
        let singleColumnBrowseResultsRenderer:SingleColumnBrowseResultsRenderer?
        enum CodingKeys: String, CodingKey {
            case singleColumnBrowseResultsRenderer = "singleColumnBrowseResultsRenderer"

        }
        init(from decoder: Decoder) throws {
            let values = try decoder.container(keyedBy: CodingKeys.self)
            singleColumnBrowseResultsRenderer = try values.decodeIfPresent(SingleColumnBrowseResultsRenderer.self, forKey: .singleColumnBrowseResultsRenderer)
        }
        struct SingleColumnBrowseResultsRenderer: Codable {
            let tabs:[Tab]?
            enum CodingKeys: String, CodingKey {
                case tabs = "tabs"

            }
            init(from decoder: Decoder) throws {
                let values = try decoder.container(keyedBy: CodingKeys.self)
                tabs = try values.decodeIfPresent([Tab].self, forKey: .tabs)
            }
            struct Tab: Codable {
                let tabRenderer:TabRenderer?
                enum CodingKeys: String, CodingKey {
                    case tabRenderer = "tabRenderer"

                }
                init(from decoder: Decoder) throws {
                    let values = try decoder.container(keyedBy: CodingKeys.self)
                    tabRenderer = try values.decodeIfPresent(TabRenderer.self, forKey: .tabRenderer)
                }
                struct TabRenderer: Codable {
                    let content:Content?
                    enum CodingKeys: String, CodingKey {
                        case content = "content"

                    }
                    init(from decoder: Decoder) throws {
                        let values = try decoder.container(keyedBy: CodingKeys.self)
                        content = try values.decodeIfPresent(Content.self, forKey: .content)
                    }
                    struct Content: Codable {
                        let sectionListRenderer:SectionListRenderer?
                        enum CodingKeys: String, CodingKey {
                            case sectionListRenderer = "sectionListRenderer"

                        }
                        init(from decoder: Decoder) throws {
                            let values = try decoder.container(keyedBy: CodingKeys.self)
                            sectionListRenderer = try values.decodeIfPresent(SectionListRenderer.self, forKey: .sectionListRenderer)
                        }
                        struct SectionListRenderer: Codable {
                            let contents:[Content]?
                            enum CodingKeys: String, CodingKey {
                                case contents = "contents"

                            }
                            init(from decoder: Decoder) throws {
                                let values = try decoder.container(keyedBy: CodingKeys.self)
                                contents = try values.decodeIfPresent([Content].self, forKey: .contents)
                            }
                            struct Content: Codable {
                                let musicCarouselShelfRenderer:MusicCarouselShelfRenderer?
                                enum CodingKeys: String, CodingKey {
                                    case musicCarouselShelfRenderer = "musicCarouselShelfRenderer"

                                }
                                init(from decoder: Decoder) throws {
                                    let values = try decoder.container(keyedBy: CodingKeys.self)
                                    musicCarouselShelfRenderer = try values.decodeIfPresent(MusicCarouselShelfRenderer.self, forKey: .musicCarouselShelfRenderer)
                                }
                                struct MusicCarouselShelfRenderer: Codable {
                                    //组头
                                    let header:Header?
                                    //内容组
                                    let contents:[Content]?
                                    enum CodingKeys: String, CodingKey {
                                        case header = "header"
                                        case contents = "contents"
                                    }
                                    init(from decoder: Decoder) throws {
                                        let values = try decoder.container(keyedBy: CodingKeys.self)
                                        header = try values.decodeIfPresent(Header.self, forKey: .header)
                                        contents = try values.decodeIfPresent([Content].self, forKey: .contents)
                                    }
                                    
                                    ///模块标题
                                    struct Header: Codable {
                                        let musicCarouselShelfBasicHeaderRenderer:MusicCarouselShelfBasicHeaderRenderer?
                                        enum CodingKeys: String, CodingKey {
                                            case musicCarouselShelfBasicHeaderRenderer = "musicCarouselShelfBasicHeaderRenderer"
                                        }
                                        init(from decoder: Decoder) throws {
                                            let values = try decoder.container(keyedBy: CodingKeys.self)
                                            musicCarouselShelfBasicHeaderRenderer = try values.decodeIfPresent(MusicCarouselShelfBasicHeaderRenderer.self, forKey: .musicCarouselShelfBasicHeaderRenderer)
                                        }
                                        struct MusicCarouselShelfBasicHeaderRenderer: Codable {
                                            let title:Title?
                                            enum CodingKeys: String, CodingKey {
                                                case title = "title"
                                            }
                                            init(from decoder: Decoder) throws {
                                                let values = try decoder.container(keyedBy: CodingKeys.self)
                                                title = try values.decodeIfPresent(Title.self, forKey: .title)
                                            }
                                            struct Title: Codable {
                                                ///一般是第0位
                                                let runs:[Run]?
                                                enum CodingKeys: String, CodingKey {
                                                    case runs = "runs"
                                                }
                                                init(from decoder: Decoder) throws {
                                                    let values = try decoder.container(keyedBy: CodingKeys.self)
                                                    runs = try values.decodeIfPresent([Run].self, forKey: .runs)
                                                }
                                                
                                                //MARK: - 文本内容，标题/作者/专辑
                                                struct Run: Codable {
                                                    ///关键文本内容（代表各级标题）
                                                    let text:String?
                                                    enum CodingKeys: String, CodingKey {
                                                        case text = "text"
                                                    }
                                                    init(from decoder: Decoder) throws {
                                                        let values = try decoder.container(keyedBy: CodingKeys.self)
                                                        text = try values.decodeIfPresent(String.self, forKey: .text)
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    ///内容模块
                                    struct Content: Codable {
                                        let musicResponsiveListItemRenderer:MusicResponsiveListItemRenderer?
                                        enum CodingKeys: String, CodingKey {
                                            case musicResponsiveListItemRenderer = "musicResponsiveListItemRenderer"

                                        }
                                        init(from decoder: Decoder) throws {
                                            let values = try decoder.container(keyedBy: CodingKeys.self)
                                            musicResponsiveListItemRenderer = try values.decodeIfPresent(MusicResponsiveListItemRenderer.self, forKey: .musicResponsiveListItemRenderer)

                                        }
                                        struct MusicResponsiveListItemRenderer: Codable {
                                            ///封面
                                            let thumbnail:Thumbnail?
                                            ///相关文本组
                                            let flexColumns:[FlexColumn]?
                                            ///导航终点
                                            let navigationEndpoint:NavigationEndpoint?
                                            enum CodingKeys: String, CodingKey {
                                                case thumbnail = "thumbnail"
                                                case flexColumns = "flexColumns"
                                                case navigationEndpoint = "navigationEndpoint"
                                            }
                                            init(from decoder: Decoder) throws {
                                                let values = try decoder.container(keyedBy: CodingKeys.self)
                                                thumbnail = try values.decodeIfPresent(Thumbnail.self, forKey: .thumbnail)
                                                flexColumns = try values.decodeIfPresent([FlexColumn].self, forKey: .flexColumns)
                                                navigationEndpoint = try values.decodeIfPresent(NavigationEndpoint.self, forKey: .navigationEndpoint)
                                            }
                                            //MARK: - 含有封面图像
                                            struct Thumbnail: Codable {
                                                let musicThumbnailRenderer:MusicThumbnailRenderer?
                                                enum CodingKeys: String, CodingKey {
                                                    case musicThumbnailRenderer = "musicThumbnailRenderer"
                                                }
                                                init(from decoder: Decoder) throws {
                                                    let values = try decoder.container(keyedBy: CodingKeys.self)
                                                    musicThumbnailRenderer = try values.decodeIfPresent(MusicThumbnailRenderer.self, forKey: .musicThumbnailRenderer)
                                                }
                                                
                                                struct MusicThumbnailRenderer: Codable {
                                                    let thumbnail:Thumbnail?
                                                    enum CodingKeys: String, CodingKey {
                                                        case thumbnail = "thumbnail"
                                                    }
                                                    init(from decoder: Decoder) throws {
                                                        let values = try decoder.container(keyedBy: CodingKeys.self)
                                                        self.thumbnail = try values.decodeIfPresent(Thumbnail.self, forKey: .thumbnail)
                                                    }
                                                    struct Thumbnail: Codable {
                                                        ///封面图片组（默认取最后一位，图像内容最大最高清）
                                                        let thumbnails:[Thumbnails]?
                                                        enum CodingKeys: String, CodingKey {
                                                            case thumbnails = "thumbnails"
                                                        }
                                                        init(from decoder: Decoder) throws {
                                                            let values = try decoder.container(keyedBy: CodingKeys.self)
                                                            self.thumbnails = try values.decodeIfPresent([Thumbnails].self, forKey: .thumbnails)
                                                        }
                                                        //MARK: - 封面图片
                                                        ///封面图片
                                                        struct Thumbnails: Codable {
                                                            ///封面图片路径
                                                            let url:String?
                                                            enum CodingKeys: String, CodingKey {
                                                                case url = "url"
                                                            }
                                                            init(from decoder: Decoder) throws {
                                                                let values = try decoder.container(keyedBy: CodingKeys.self)
                                                                url = try values.decodeIfPresent(String.self, forKey: .url)
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            //MARK: - 文本信息
                                            struct FlexColumn: Codable {
                                                let musicResponsiveListItemFlexColumnRenderer:MusicResponsiveListItemFlexColumnRenderer?
                                                enum CodingKeys: String, CodingKey {
                                                    case musicResponsiveListItemFlexColumnRenderer = "musicResponsiveListItemFlexColumnRenderer"
                                                }
                                                init(from decoder: Decoder) throws {
                                                    let values = try decoder.container(keyedBy: CodingKeys.self)
                                                    musicResponsiveListItemFlexColumnRenderer = try values.decodeIfPresent(MusicResponsiveListItemFlexColumnRenderer.self, forKey: .musicResponsiveListItemFlexColumnRenderer)
                                                }
                                                struct MusicResponsiveListItemFlexColumnRenderer: Codable {
                                                    let text:Text?
                                                    enum CodingKeys: String, CodingKey {
                                                        case text = "text"
                                                    }
                                                    init(from decoder: Decoder) throws {
                                                        let values = try decoder.container(keyedBy: CodingKeys.self)
                                                        text = try values.decodeIfPresent(Text.self, forKey: .text)
                                                    }
                                                    struct Text: Codable {
                                                        let runs:[Run]?
                                                        enum CodingKeys: String, CodingKey {
                                                            case runs = "runs"
                                                        }
                                                        init(from decoder: Decoder) throws {
                                                            let values = try decoder.container(keyedBy: CodingKeys.self)
                                                            runs = try values.decodeIfPresent([Run].self, forKey: .runs)
                                                        }
                                                        struct Run: Codable {
                                                            let text:String?
                                                            enum CodingKeys: String, CodingKey {
                                                                case text = "text"
                                                            }
                                                            init(from decoder: Decoder) throws {
                                                                let values = try decoder.container(keyedBy: CodingKeys.self)
                                                                text = try values.decodeIfPresent(String.self, forKey: .text)
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            //MARK: - 导航终点信息
                                            struct NavigationEndpoint: Codable {
                                                //预览终点
                                                let browseEndpoint:BrowseEndpoint?
                                                enum CodingKeys: String, CodingKey {
                                                    case browseEndpoint = "browseEndpoint"
                                                }
                                                init(from decoder: Decoder) throws {
                                                    let values = try decoder.container(keyedBy: CodingKeys.self)
                                                    browseEndpoint = try values.decodeIfPresent(BrowseEndpoint.self, forKey: .browseEndpoint)
                                                }
                                                struct BrowseEndpoint: Codable {
                                                    let browseId:String?
                                                    let browseEndpointContextSupportedConfigs:BrowseEndpointContextSupportedConfigs?
                                                    enum CodingKeys: String, CodingKey {
                                                        case browseId = "browseId"
                                                        case browseEndpointContextSupportedConfigs = "browseEndpointContextSupportedConfigs"
                                                    }
                                                    init(from decoder: Decoder) throws {
                                                        let values = try decoder.container(keyedBy: CodingKeys.self)
                                                        browseId = try values.decodeIfPresent(String.self, forKey: .browseId)
                                                        browseEndpointContextSupportedConfigs = try values.decodeIfPresent(BrowseEndpointContextSupportedConfigs.self, forKey: .browseEndpointContextSupportedConfigs)
                                                    }
                                                    struct BrowseEndpointContextSupportedConfigs: Codable {
                                                        let browseEndpointContextMusicConfig:BrowseEndpointContextMusicConfig?
                                                        enum CodingKeys: String, CodingKey {
                                                            case browseEndpointContextMusicConfig = "browseEndpointContextMusicConfig"
                                                        }
                                                        init(from decoder: Decoder) throws {
                                                            let values = try decoder.container(keyedBy: CodingKeys.self)
                                                            browseEndpointContextMusicConfig = try values.decodeIfPresent(BrowseEndpointContextMusicConfig.self, forKey: .browseEndpointContextMusicConfig)
                                                        }
                                                        struct BrowseEndpointContextMusicConfig: Codable {
                                                            let pageType:String?
                                                            enum CodingKeys: String, CodingKey {
                                                                case pageType = "pageType"
                                                            }
                                                            init(from decoder: Decoder) throws {
                                                                let values = try decoder.container(keyedBy: CodingKeys.self)
                                                                pageType = try values.decodeIfPresent(String.self, forKey: .pageType)
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
