package com.its.vms.domain;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *  DTO Class
 */
@Data
public class VmsFormManager implements Serializable {
    private static final long serialVersionUID = 1L;

    private int formWidth;
    private int formHeight;

    private int totalCount;
    private int objectCount;

    private List<VmsForm> objects;

    public VmsFormManager(int formWidth, int formHeight) {
        this.formWidth = formWidth;
        this.formHeight = formHeight;
        this.totalCount = 0;
        this.objectCount = 0;
        this.objects = new ArrayList<>();
    }

    public void clear() {
        this.objectCount = 0;
        this.objects.forEach(obj -> {
            obj.clear();
        });
    }

    public VmsForm getItem(int idx) {
        if (this.objects.size() > idx) {
            return this.objects.get(idx);
        }
        return null;
    }

//    public int addForm(VmsForm form) {
//        this.objects.add(form);
//        this.objectCount = this.objects.size();
//        return this.objectCount;
//    }

    public VmsForm addForm(Integer vmsFormId, int dnldFormNo) {
        VmsForm form = null;
        if (this.objectCount < this.totalCount) {
            form = getItem(this.objectCount);
        }
        else {
            form = new VmsForm(vmsFormId);
            form.init(this.formWidth, this.formHeight);
            this.objects.add(form);
            this.totalCount++;
        }
        this.objectCount++;
        form.setDnldFormNo(dnldFormNo);
        return form;
    }

    public int count() { return this.objectCount; }
    public int total() { return this.totalCount; }

}

