//
//  MPPositive_JsonSearchSuggestions.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/5/12.
//

import UIKit

struct JsonSearchSuggestions: 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 searchSuggestionsSectionRenderer:SearchSuggestionsSectionRenderer?
        enum CodingKeys: String, CodingKey {
            case searchSuggestionsSectionRenderer = "searchSuggestionsSectionRenderer"
        }
        init(from decoder: Decoder) throws {
            let values = try decoder.container(keyedBy: CodingKeys.self)
            searchSuggestionsSectionRenderer = try values.decodeIfPresent(SearchSuggestionsSectionRenderer.self, forKey: .searchSuggestionsSectionRenderer)
        }
        struct SearchSuggestionsSectionRenderer: 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 searchSuggestionRenderer:SearchSuggestionRenderer?
                ///音乐建议
                let musicResponsiveListItemRenderer:MusicResponsiveListItemRenderer?
                enum CodingKeys: String, CodingKey {
                    case searchSuggestionRenderer = "searchSuggestionRenderer"
                    case musicResponsiveListItemRenderer = "musicResponsiveListItemRenderer"
                }
                init(from decoder: Decoder) throws {
                    let values = try decoder.container(keyedBy: CodingKeys.self)
                    searchSuggestionRenderer = try values.decodeIfPresent(SearchSuggestionRenderer.self, forKey: .searchSuggestionRenderer)
                    musicResponsiveListItemRenderer = try values.decodeIfPresent(MusicResponsiveListItemRenderer.self, forKey: .musicResponsiveListItemRenderer)
                }
                //MARK: - 词条建议
                struct SearchSuggestionRenderer: Codable {
                    let suggestion:Suggestion?
                    enum CodingKeys: String, CodingKey {
                        case suggestion = "suggestion"
                    }
                    init(from decoder: Decoder) throws {
                        let values = try decoder.container(keyedBy: CodingKeys.self)
                        suggestion = try values.decodeIfPresent(Suggestion.self, forKey: .suggestion)
                    }
                    struct Suggestion: 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 MusicResponsiveListItemRenderer: Codable {
                    let thumbnail:Thumbnail?
                    let flexColumns:[FlexColumn]?
                    enum CodingKeys: String, CodingKey {
                        case thumbnail = "thumbnail"
                        case flexColumns = "flexColumns"
                    }
                    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)
                    }
                    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?
                                    let width:CGFloat?
                                    let height:CGFloat?
                                    enum CodingKeys: String, CodingKey {
                                        case url = "url"
                                        case width = "width"
                                        case height = "height"
                                    }
                                    init(from decoder: Decoder) throws {
                                        let values = try decoder.container(keyedBy: CodingKeys.self)
                                        url = try values.decodeIfPresent(String.self, forKey: .url)
                                        width = try values.decodeIfPresent(CGFloat.self, forKey: .width)
                                        height = try values.decodeIfPresent(CGFloat.self, forKey: .height)
                                    }
                                }
                            }
                        }
                    }
                    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)
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
