package me.chyxion.tigon.service;

import java.util.Map;
import java.util.Collection;
import me.chyxion.tigon.mybatis.Search;
import me.chyxion.tigon.model.BaseModel;
import me.chyxion.tigon.model.ViewModel;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.NotEmpty;
import me.chyxion.tigon.validation.annotation.NotNullOrBlank;

/**
 * @version 0.0.1
 * @since 0.0.1
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Jun 21, 2016 10:02:10 AM
 */
public interface BaseCrudService
    <PrimaryKey, Model extends BaseModel<PrimaryKey>>
    extends BaseQueryService<PrimaryKey, Model>,
    BaseDeleteService<PrimaryKey> {

    /**
     * @param model form
     * @return view model
     */
    @NotNull ViewModel<Model> create(@NotNull Model model);

    /**
     * create model
     * @param models model
     */
    Collection<ViewModel<Model>> create(@NotEmpty Collection<Model> models);

    /**
     * @param model model
     * @return view model
     */
    @NotNull ViewModel<Model> update(@NotNull Model model);

    /**
     * update model by search
     * @param model model sample
     * @param search search
     * @return updated rows
     */
    int update(@NotNull Model model, @NotNull Search search);

    /**
     * update model by primary key
     * @param model update map
     * @param primaryKey
     * @return updated rows
     */
    int update(@NotEmpty Map<String, ?> model, @NotNullOrBlank PrimaryKey primaryKey);

    /**
     * update model by search
     * @param model update map
     * @param search search
     * @return updated rows
     */
    int update(@NotEmpty Map<String, ?> model, @NotNull Search search);
}
