package fcb.project.manager.core.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import fcb.project.manager.base.entity.*;
import fcb.project.manager.base.enums.AuditStatus;
import fcb.project.manager.base.enums.DeleteStatus;
import fcb.project.manager.base.enums.HouseStatus;
import fcb.project.manager.base.enums.SysUserRoleEnums;
import fcb.project.manager.base.param.house.QueryHouseParam;
import fcb.project.manager.base.param.usedEstate.QueryUsedEstate;
import fcb.project.manager.base.service.ITmUsedEstateService;
import fcb.project.manager.base.service.custom.PanoService;
import fcb.project.manager.base.service.impl.*;
import fcb.project.manager.base.utils.DataUtils;
import fcb.project.manager.base.utils.DateUtil;
import fcb.project.manager.base.utils.ExcelUtil;
import fcb.project.manager.base.vo.house.HouseVO;
import fcb.project.manager.core.feignInterfaces.SceneFeign;
import fdage.back.sdk.base.entity.Result;
import fdage.back.sdk.base.entity.ViewResult;
import fdage.back.sdk.base.enums.ResultCodeEnum;
import fdage.back.sdk.base.exception.CommonBaseException;
import fdage.back.sdk.base.uuid.SnowFlakeUUidUtils;
import fdage.back.sdk.core.alibabaUtils.AlibabaOssHelper;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 2 * @Author: Abner
 * 3 * @Date: 2021/1/7 17:38
 * 4
 */
@Api(tags = "二手房小区相关接口")
@RestController
@RequestMapping("fcb/project/usedestate")
@Log4j2
@Validated
public class UsedEstateManagerController extends BaseController{

    @Autowired
    private ITmUsedEstateService tmUsedEstateService;

    public static String IMAGE_PATH = ".+(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png)";

    @PostMapping("/addEstate")
    @ApiOperation(value = "创建二手房小区")
    public ViewResult addNewHouse(@RequestBody TmUsedEstate tmUsedEstate){
        Map<String, Object> map = tmUsedEstateService.addProject(tmUsedEstate, getContextUserInfo());
        return ViewResult.success(map);
    }

    @PostMapping("/getEstateDetail")
    @ApiOperation(value = "根据小区ID获取小区详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gardenId", value = "小区ID", paramType = "query", required = true, dataType = "String"),
    })
    public Result<Object> getEstateDetail(@RequestBody QueryUsedEstate queryUsedEstate){
        return Result.success();

    }

    @PostMapping("/queryOrSearchList")
    @ApiOperation(value = "根据条件拉取所有小区 , 支持分页")
    @ApiResponses({
            @ApiResponse(code = 0,message = "成功",response = TmUsedEstate.class)
    })
    public ViewResult<TmUsedEstate> getHouseList(@RequestBody QueryUsedEstate queryUsedEstate) {
        IPage<TmUsedEstate> resultPage = tmUsedEstateService.listProject(queryUsedEstate, getContextUserInfo(), getToken());
        return ViewResult.success(DataUtils.assembleResult(resultPage.getTotal(), resultPage.getPages(),
                resultPage.getCurrent(), resultPage.getRecords()));
    }

    @GetMapping("/usedEsDetailWithoutAuth")
    @ApiOperation(value = "根据二手房小区ID获取小区详情-无需授权，给H5使用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gardenId", value = "小区ID", paramType = "query", required = true, dataType = "String"),
    })
    @ApiResponses({
            @ApiResponse(code = 0,message = "成功",response = TmUsedEstate.class)
    })
    public Result<Object> usedEsDetailWithoutAuth(@RequestBody QueryUsedEstate queryUsedEstate){
//        if(StringUtils.isBlank(houseId)){
//            return Result.failure("房源ID不能为空");
//        }
//        TmHouse tmHouse = tmHouseService.getById(houseId);
//        if(null == tmHouse || tmHouse.getIsDelete().compareTo(1) == 0){
//            return Result.failure("房源不存在");
//        }
        return null;
    }

    @PostMapping("/submitAudit")
    @ApiOperation(value = "提交审核记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gardenId", value = "二手小区ID", paramType = "query", required = true, dataType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    @ApiResponses({
            @ApiResponse(code = 0,message = "成功",reference = "auditId")
    })
    public Result<Object> addNewAudit(@RequestBody QueryUsedEstate queryUsedEstate){

        return Result.success();

    }

    @PostMapping("/dismissAudit")
    @ApiOperation(value = "撤销审核记录-")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gardenId", value = "二手小区ID", paramType = "query", required = true, dataType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public Result<Object> dismissAudit(@RequestBody QueryUsedEstate queryUsedEstate){

        return Result.success();
    }

    @PostMapping("/deleteEstate")
    @ApiOperation(value = "删除小区信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gardenId", value = "二手小区ID", paramType = "query", required = true, dataType = "String"),
    })
    public ViewResult deleteHouse(@RequestBody QueryUsedEstate queryUsedEstate){
        return ViewResult.success();
    }

    @PostMapping("/listEstate")
    @ApiOperation("获取所有当前已创建的所有小区")
    public ViewResult<List<String>> getHouseList() {
        return ViewResult.success();

    }

    @PostMapping("/getShareLinks")
    @ApiOperation(value = "根据房源ID获取房源所有分享链接")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gardenId", value = "二手小区ID", paramType = "query", required = true, dataType = "String"),
    })
    public Result<Object> getShareLinks(@RequestBody QueryUsedEstate queryUsedEstate){
        return Result.success();
    }

}
