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

import static cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper.CasbinRuleDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

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

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 CasbinRuleMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<CasbinRule>, CommonUpdateMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    BasicColumn[] selectList = BasicColumn.columnList(id, ptype, v0, v1, v2, v3, v4, v5);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="CasbinRuleResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="ptype", property="ptype", jdbcType=JdbcType.VARCHAR),
        @Result(column="v0", property="v0", jdbcType=JdbcType.VARCHAR),
        @Result(column="v1", property="v1", jdbcType=JdbcType.VARCHAR),
        @Result(column="v2", property="v2", jdbcType=JdbcType.VARCHAR),
        @Result(column="v3", property="v3", jdbcType=JdbcType.VARCHAR),
        @Result(column="v4", property="v4", jdbcType=JdbcType.VARCHAR),
        @Result(column="v5", property="v5", jdbcType=JdbcType.VARCHAR)
    })
    List<CasbinRule> selectMany(SelectStatementProvider selectStatement);

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

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

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

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

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    default int insert(CasbinRule row) {
        return MyBatis3Utils.insert(this::insert, row, casbinRule, c ->
            c.map(id).toProperty("id")
            .map(ptype).toProperty("ptype")
            .map(v0).toProperty("v0")
            .map(v1).toProperty("v1")
            .map(v2).toProperty("v2")
            .map(v3).toProperty("v3")
            .map(v4).toProperty("v4")
            .map(v5).toProperty("v5")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    default int insertMultiple(Collection<CasbinRule> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, casbinRule, c ->
            c.map(id).toProperty("id")
            .map(ptype).toProperty("ptype")
            .map(v0).toProperty("v0")
            .map(v1).toProperty("v1")
            .map(v2).toProperty("v2")
            .map(v3).toProperty("v3")
            .map(v4).toProperty("v4")
            .map(v5).toProperty("v5")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    default int insertSelective(CasbinRule row) {
        return MyBatis3Utils.insert(this::insert, row, casbinRule, c ->
            c.map(id).toPropertyWhenPresent("id", row::getId)
            .map(ptype).toPropertyWhenPresent("ptype", row::getPtype)
            .map(v0).toPropertyWhenPresent("v0", row::getV0)
            .map(v1).toPropertyWhenPresent("v1", row::getV1)
            .map(v2).toPropertyWhenPresent("v2", row::getV2)
            .map(v3).toPropertyWhenPresent("v3", row::getV3)
            .map(v4).toPropertyWhenPresent("v4", row::getV4)
            .map(v5).toPropertyWhenPresent("v5", row::getV5)
        );
    }

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

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

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

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

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

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    static UpdateDSL<UpdateModel> updateAllColumns(CasbinRule row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalTo(row::getId)
                .set(ptype).equalTo(row::getPtype)
                .set(v0).equalTo(row::getV0)
                .set(v1).equalTo(row::getV1)
                .set(v2).equalTo(row::getV2)
                .set(v3).equalTo(row::getV3)
                .set(v4).equalTo(row::getV4)
                .set(v5).equalTo(row::getV5);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(CasbinRule row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalToWhenPresent(row::getId)
                .set(ptype).equalToWhenPresent(row::getPtype)
                .set(v0).equalToWhenPresent(row::getV0)
                .set(v1).equalToWhenPresent(row::getV1)
                .set(v2).equalToWhenPresent(row::getV2)
                .set(v3).equalToWhenPresent(row::getV3)
                .set(v4).equalToWhenPresent(row::getV4)
                .set(v5).equalToWhenPresent(row::getV5);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    default int updateByPrimaryKey(CasbinRule row) {
        return update(c ->
            c.set(ptype).equalTo(row::getPtype)
            .set(v0).equalTo(row::getV0)
            .set(v1).equalTo(row::getV1)
            .set(v2).equalTo(row::getV2)
            .set(v3).equalTo(row::getV3)
            .set(v4).equalTo(row::getV4)
            .set(v5).equalTo(row::getV5)
            .where(id, isEqualTo(row::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule")
    default int updateByPrimaryKeySelective(CasbinRule row) {
        return update(c ->
            c.set(ptype).equalToWhenPresent(row::getPtype)
            .set(v0).equalToWhenPresent(row::getV0)
            .set(v1).equalToWhenPresent(row::getV1)
            .set(v2).equalToWhenPresent(row::getV2)
            .set(v3).equalToWhenPresent(row::getV3)
            .set(v4).equalToWhenPresent(row::getV4)
            .set(v5).equalToWhenPresent(row::getV5)
            .where(id, isEqualTo(row::getId))
        );
    }
}
