package me.chyxion.tigon.mybatis;

import org.apache.commons.lang3.StringUtils;

/**
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * 2017/1/23 17:04
 */
class OrSearchProcessor implements SearchProcessor {

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean accept(SearchProcessArgs args) {
        return CriterionType.OR.equals(args.getCriterion().getType());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void process(SearchProcessArgs args) {
        if (args.isHasPrevCol()) {
            args.append(" or ");
        }
        else {
            args.setHasPrevOrCol(true);
        }
        final Search search = args.getCriterion().getSearch();
        if (StringUtils.isBlank(search.table())) {
            search.table(args.getTable());
        }
        args.getResult().addAll(search.assemble(true));
    }
}
