//
//  PhotoModel.swift
//  CareAxiom MVVM Assignment
//
//  Created by Sobhan Asim on 12/09/2021.
//


import Foundation


struct PhotoModel: Codable {
    var albumId     : Int?
    var id          : Int?
    var title       : String?
    var url         : String?
    var thumbnailUrl: String?
    
    private enum CodingKeys: String, CodingKey {
        case albumId
        case id
        case title
        case url
        case thumbnailUrl
    }
    
    static func initPhotoModel(fromJson json: [String:Any]) -> PhotoModel {
        var photo = PhotoModel()
        photo.albumId       = json[PhotoModel.CodingKeys.albumId.rawValue] as? Int
        photo.id            = json[PhotoModel.CodingKeys.id.rawValue] as? Int
        photo.title         = json[PhotoModel.CodingKeys.title.rawValue] as? String
        photo.url           = json[PhotoModel.CodingKeys.url.rawValue] as? String
        photo.thumbnailUrl  = json[PhotoModel.CodingKeys.thumbnailUrl.rawValue] as? String
        
        return photo
        
    }
    
}

struct PhotoAlbumModel: Codable {
    var photos: [PhotoModel]? = []
    
    static func initPhotoAlbum(fromPhotos photos: [PhotoModel]) -> PhotoAlbumModel {
        var album = PhotoAlbumModel()
        
        album.photos?.append(contentsOf: photos)
        
        return album
        
    }
}
