
import Foundation

struct GetStoriesModel: Codable {
    
    var apiStatus: Int?
    var stories: [UserData]?
    
    enum CodingKeys: String, CodingKey {
        case apiStatus = "api_status"
        case stories
    }
    
}

struct CreateStoryModel: Codable {
    
    let apiStatus, storyID: Int?
    
    enum CodingKeys: String, CodingKey {
        case apiStatus = "api_status"
        case storyID = "story_id"
    }
    
}

struct StoryModel : Codable {
    
    let api_status : Int?
    let story : UserDataStory?
    
    enum CodingKeys: String, CodingKey {
        
        case api_status = "api_status"
        case story = "story"
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        api_status = try values.decodeIfPresent(Int.self, forKey: .api_status)
        story = try values.decodeIfPresent(UserDataStory.self, forKey: .story)
    }
    
}


struct StoriesResponse: Codable {
    
    var api_status: Int?
    var stories: [UserData]?
    
    enum CodingKeys: String, CodingKey {
        case api_status = "api_status"
        case stories = "stories"
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        api_status = try values.decodeIfPresent(Int.self, forKey: .api_status)
        stories = try values.decodeIfPresent([UserData].self, forKey: .stories)
    }
    
}

struct UserDataStory: Codable {
    
    var id: IntString?
    var user_id: IntString?
    var title: String?
    var description: String?
    var posted: String?
    var expire: String?
    var thumbnail: String?
    let thumb : Thumb?
    var images: [JSONAny]?
    var user_data: UserData?
    var videos: [StoryVideoModel]?
    var is_owner: Bool?
    var reaction: ReactionModel?
    var is_viewed: Int?
    var time_text: String?
    var view_count: Int?
    
    enum CodingKeys: String, CodingKey {
        case id = "id"
        case user_id = "user_id"
        case title = "title"
        case description = "description"
        case posted = "posted"
        case expire = "expire"
        case thumbnail = "thumbnail"
        case thumb = "thumb"
        case images = "images"
        case user_data = "user_data"
        case videos = "videos"
        case is_owner = "is_owner"
        case reaction = "reaction"
        case is_viewed = "is_viewed"
        case time_text = "time_text"
        case view_count = "view_count"
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        id = try values.decodeIfPresent(IntString.self, forKey: .id)
        user_id = try values.decodeIfPresent(IntString.self, forKey: .user_id)
        title = try values.decodeIfPresent(String.self, forKey: .title)
        description = try values.decodeIfPresent(String.self, forKey: .description)
        posted = try values.decodeIfPresent(String.self, forKey: .posted)
        expire = try values.decodeIfPresent(String.self, forKey: .expire)
        thumbnail = try values.decodeIfPresent(String.self, forKey: .thumbnail)
        thumb = try values.decodeIfPresent(Thumb.self, forKey: .thumb)
        images = try values.decodeIfPresent([JSONAny].self, forKey: .images)
        user_data = try values.decodeIfPresent(UserData.self, forKey: .user_data)
        videos = try values.decodeIfPresent([StoryVideoModel].self, forKey: .videos)
        is_owner = try values.decodeIfPresent(Bool.self, forKey: .is_owner)
        reaction = try values.decodeIfPresent(ReactionModel.self, forKey: .reaction)
        view_count = try values.decodeIfPresent(Int.self, forKey: .view_count)
        is_viewed = try values.decodeIfPresent(Int.self, forKey: .is_viewed)
        time_text = try values.decodeIfPresent(String.self, forKey: .time_text)
    }
    
}

struct StoryVideoModel: Codable {
    
    var id, storyID, type: String?
    var filename: String?
    var expire: String?
    
    enum CodingKeys: String, CodingKey {
        case id
        case storyID = "story_id"
        case type, filename, expire
    }
    
}

struct Thumb : Codable {
    
    let id : String?
    let story_id : String?
    let type : String?
    let filename : String?
    let expire : String?
    
    enum CodingKeys: String, CodingKey {
        
        case id = "id"
        case story_id = "story_id"
        case type = "type"
        case filename = "filename"
        case expire = "expire"
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        id = try values.decodeIfPresent(String.self, forKey: .id)
        story_id = try values.decodeIfPresent(String.self, forKey: .story_id)
        type = try values.decodeIfPresent(String.self, forKey: .type)
        filename = try values.decodeIfPresent(String.self, forKey: .filename)
        expire = try values.decodeIfPresent(String.self, forKey: .expire)
    }
    
}
