package com.mariusht.puremvcexample.model
{
    import com.mariusht.puremvcexample.model.vo.OwnerVO;
    
    import mx.collections.ArrayCollection;
    
    import org.puremvc.as3.interfaces.IProxy;
    import org.puremvc.as3.patterns.proxy.Proxy;

    public class CarOwnersProxy extends Proxy implements IProxy
    {
        public static const NAME:String = 'CarOwnersProxy';
        
        public function CarOwnersProxy()
        {
            super(NAME, new ArrayCollection());
        }
        
        public function removeOwner(owner:OwnerVO):void
        {
            for(var i:int=0; i<owners.length; i++)
            {
                if(owners.getItemAt(i).name == owner.name)
                {
                    owners.removeItemAt(i);
                    var carsProxy:CarsProxy = facade.retrieveProxy(CarsProxy.NAME) as CarsProxy;
                    carsProxy.removeMyCar(owner);
                    break;
                }
            }
        }
        
        public function get owners():ArrayCollection
        {
            return data as ArrayCollection;
        }
    }
}