package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper;

import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

import cn.skcks.matrix.v2.orm.mybatis.dynamic.model.Role;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface RoleMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<Role>, CommonUpdateMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    BasicColumn[] selectList = BasicColumn.columnList(RoleDynamicSqlSupport.id, RoleDynamicSqlSupport.role.role, RoleDynamicSqlSupport.name, RoleDynamicSqlSupport.systemId, RoleDynamicSqlSupport.active);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="RoleResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="role", property="role", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="system_id", property="systemId", jdbcType=JdbcType.VARCHAR),
        @Result(column="active", property="active", jdbcType=JdbcType.BIT)
    })
    List<Role> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("RoleResult")
    Optional<Role> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, RoleDynamicSqlSupport.role, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, RoleDynamicSqlSupport.role, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
            c.where(RoleDynamicSqlSupport.id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default int insert(Role row) {
        return MyBatis3Utils.insert(this::insert, row, RoleDynamicSqlSupport.role, c ->
            c.map(RoleDynamicSqlSupport.id).toProperty("id")
            .map(RoleDynamicSqlSupport.role.role).toProperty("role")
            .map(RoleDynamicSqlSupport.name).toProperty("name")
            .map(RoleDynamicSqlSupport.systemId).toProperty("systemId")
            .map(RoleDynamicSqlSupport.active).toProperty("active")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default int insertMultiple(Collection<Role> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, RoleDynamicSqlSupport.role, c ->
            c.map(RoleDynamicSqlSupport.id).toProperty("id")
            .map(RoleDynamicSqlSupport.role.role).toProperty("role")
            .map(RoleDynamicSqlSupport.name).toProperty("name")
            .map(RoleDynamicSqlSupport.systemId).toProperty("systemId")
            .map(RoleDynamicSqlSupport.active).toProperty("active")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default int insertSelective(Role row) {
        return MyBatis3Utils.insert(this::insert, row, RoleDynamicSqlSupport.role, c ->
            c.map(RoleDynamicSqlSupport.id).toPropertyWhenPresent("id", row::getId)
            .map(RoleDynamicSqlSupport.role.role).toPropertyWhenPresent("role", row::getRole)
            .map(RoleDynamicSqlSupport.name).toPropertyWhenPresent("name", row::getName)
            .map(RoleDynamicSqlSupport.systemId).toPropertyWhenPresent("systemId", row::getSystemId)
            .map(RoleDynamicSqlSupport.active).toPropertyWhenPresent("active", row::getActive)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default Optional<Role> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, RoleDynamicSqlSupport.role, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default List<Role> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, RoleDynamicSqlSupport.role, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default List<Role> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, RoleDynamicSqlSupport.role, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default Optional<Role> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(RoleDynamicSqlSupport.id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, RoleDynamicSqlSupport.role, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    static UpdateDSL<UpdateModel> updateAllColumns(Role row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(RoleDynamicSqlSupport.id).equalTo(row::getId)
                .set(RoleDynamicSqlSupport.role.role).equalTo(row::getRole)
                .set(RoleDynamicSqlSupport.name).equalTo(row::getName)
                .set(RoleDynamicSqlSupport.systemId).equalTo(row::getSystemId)
                .set(RoleDynamicSqlSupport.active).equalTo(row::getActive);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Role row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(RoleDynamicSqlSupport.id).equalToWhenPresent(row::getId)
                .set(RoleDynamicSqlSupport.role.role).equalToWhenPresent(row::getRole)
                .set(RoleDynamicSqlSupport.name).equalToWhenPresent(row::getName)
                .set(RoleDynamicSqlSupport.systemId).equalToWhenPresent(row::getSystemId)
                .set(RoleDynamicSqlSupport.active).equalToWhenPresent(row::getActive);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default int updateByPrimaryKey(Role row) {
        return update(c ->
            c.set(RoleDynamicSqlSupport.role.role).equalTo(row::getRole)
            .set(RoleDynamicSqlSupport.name).equalTo(row::getName)
            .set(RoleDynamicSqlSupport.systemId).equalTo(row::getSystemId)
            .set(RoleDynamicSqlSupport.active).equalTo(row::getActive)
            .where(RoleDynamicSqlSupport.id, isEqualTo(row::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role")
    default int updateByPrimaryKeySelective(Role row) {
        return update(c ->
            c.set(RoleDynamicSqlSupport.role.role).equalToWhenPresent(row::getRole)
            .set(RoleDynamicSqlSupport.name).equalToWhenPresent(row::getName)
            .set(RoleDynamicSqlSupport.systemId).equalToWhenPresent(row::getSystemId)
            .set(RoleDynamicSqlSupport.active).equalToWhenPresent(row::getActive)
            .where(RoleDynamicSqlSupport.id, isEqualTo(row::getId))
        );
    }
}
