package com.njcn.rdms.module.project.dal.mysql.status;

import com.njcn.rdms.framework.mybatis.core.mapper.BaseMapperX;
import com.njcn.rdms.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.njcn.rdms.module.project.dal.dataobject.status.ObjectStatusModelDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface ObjectStatusModelMapper extends BaseMapperX<ObjectStatusModelDO> {

    default ObjectStatusModelDO selectByObjectTypeAndStatusCode(String objectType, String statusCode) {
        return selectOne(new LambdaQueryWrapperX<ObjectStatusModelDO>()
                .eq(ObjectStatusModelDO::getObjectType, objectType)
                .eq(ObjectStatusModelDO::getStatusCode, statusCode));
    }

    default ObjectStatusModelDO selectByObjectTypeAndStatusCodeEnabled(String objectType, String statusCode) {
        return selectOne(new LambdaQueryWrapperX<ObjectStatusModelDO>()
                .eq(ObjectStatusModelDO::getObjectType, objectType)
                .eq(ObjectStatusModelDO::getStatusCode, statusCode)
                .eq(ObjectStatusModelDO::getStatus, 0));
    }

    default List<ObjectStatusModelDO> selectListByObjectType(String objectType) {
        return selectList(new LambdaQueryWrapperX<ObjectStatusModelDO>()
                .eq(ObjectStatusModelDO::getObjectType, objectType)
                .orderByAsc(ObjectStatusModelDO::getSort));
    }

}
