//
//  CategoryParser.swift
//  NearbyStores
//
//  Created by Amine on 7/12/18.
//  Copyright © 2018 Amine. All rights reserved.
//

import UIKit

class CFParser: Parser {
    
    func parse() -> [CustomFields] {
        
        var list = [CustomFields]()
        
        if let myResult = self.result {
            
            

           
            
            if myResult.count > 0 {
                
                let size = myResult.count-1
                
                for index in 0...size {
                    
                    let object = myResult[ String(index) ]
                 
                    let myObject = CustomFields()
                    
                    myObject.id = object["id"].intValue
                    myObject.label = object["label"].stringValue
                
                
                    
                    let icontent = object["fields"].stringValue
                    let parser = CFieldParser(array: icontent)
                                    
                    let field_list = parser.parse(id: myObject.id )
                            
                    for field in field_list {
                        myObject.fields.append(field)
                    }
                    
                    list.append(myObject)
                    
                }
                
                
            }
            
            
            return list
        }
        
        return []
    }
}
