package com.example.module.admin.mgr;

import com.example.frame.utils.IDgenerator;
import com.example.frame.utils.Message;
import com.example.frame.base.ErrorType;
import com.example.frame.base.Token;
import com.example.frame.utils.MapperUtil;
import com.example.frame.utils.ValidationUtil;
import com.example.module.admin.ent.Mapping;
import com.example.module.admin.req.MappingCreateRequest;
import com.example.module.admin.req.MappingDeleteRequest;
import com.example.module.admin.req.MappingFindRequest;
import com.example.module.admin.req.MappingUpdateRequest;
import com.example.module.admin.rsp.MappingCreateResponse;
import com.example.module.admin.rsp.MappingDeleteResponse;
import com.example.module.admin.rsp.MappingFindResponse;
import com.example.module.admin.rsp.MappingUpdateResponse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * MAPPING - 映射
 *
 * @author author
 * @version 0.0.1
 * @since 2019-09-28
 */
@Service
public class MappingManagerImpl implements MappingManager {

    /**
     * 插入
     *
     * @param request 请求对象
     * @param token   令牌
     * @return 响应
     */
    public MappingCreateResponse create(MappingCreateRequest request, Token token) {
        MappingCreateResponse response = new MappingCreateResponse();

        ValidationUtil.validate(request, response);
        if (response.hasError()) {
            return response;
        }

        long id = IDgenerator.nextId();
        Mapping entity = MapperUtil.map(request, Mapping.class);
        entity.setId(id);


        return response;
    }

    /**
     * 逻辑删除
     *
     * @param request 请求对象
     * @param token   令牌
     * @return 响应
     */
    public MappingDeleteResponse delete(MappingDeleteRequest request, Token token) {
        MappingDeleteResponse response = new MappingDeleteResponse();

        ValidationUtil.validate(request, response);
        if (response.hasError()) {
            return response;
        }


        return response;
    }

    /**
     * 更新
     *
     * @param request 请求对象
     * @param token   令牌
     * @return 响应
     */
    public MappingUpdateResponse update(MappingUpdateRequest request, Token token) {
        MappingUpdateResponse response = new MappingUpdateResponse();

        ValidationUtil.validate(request, response);
        if (response.hasError()) {
            return response;
        }


        return response;
    }

    /**
     * 查询
     *
     * @param request 请求对象
     * @param token   令牌
     * @return 响应
     */
    @Transactional(readOnly = true)
    public MappingFindResponse find(MappingFindRequest request, Token token) {
        MappingFindResponse response = new MappingFindResponse();

        ValidationUtil.validate(request, response);
        if (response.hasError()) {
            return response;
        }

        return response;
    }
}
