package com.dayou.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dayou.common.BaseEntity;
import com.dayou.dto.TaskRecordDTO;
import com.dayou.vo.*;
import com.dayou.workflow.annotation.FinishTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.service.IPersonalTargetService;
import com.dayou.entity.PersonalTarget;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 个贷估价对象
 *
 * @author wucl
 * @since 2024-03-01
 */
@RestController
@RequestMapping("personalTarget")
@Slf4j
public class PersonalTargetController extends BaseController {
    @Autowired
    private IPersonalTargetService personalTargetService;

    /**
    * 个贷估价对象列表
    */
    @GetMapping("")
    public RestResponse<Page<PersonalTarget>> page(PersonalTarget personalTarget, Page page){
        Page<PersonalTarget> pages=personalTargetService.selectPage(page,personalTarget);
        return RestResponse.data(pages);
    }

    /**
     * 个贷估价对象详情
     */
    @GetMapping("/{personalId}")
    public RestResponse<PersonalTarget> detail(@PathVariable Long personalId){
        PersonalTarget xPersonalTarget =personalTargetService.detail(personalId);
        return RestResponse.data(xPersonalTarget);
     }

    /**
     * 个贷估价对象新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody PersonalTarget personalTarget) {
        Boolean ret = personalTargetService.add(personalTarget);
        return RestResponse.data(ret);
    }

    /**
     * 个贷估价对象更新评估价格
     */
    @FinishTask
    @PutMapping("")
    public RestResponse<Boolean> updatePrice(@RequestBody @Valid TaskRecordDTO<PersonalTarget> taskRecordDTO) {
        Boolean ret = personalTargetService.updatePrice(taskRecordDTO);
        return RestResponse.data(ret);
    }

    /**
     * 个贷估价对象更新 产品类型
     */
    @PutMapping("/feedback")
    public RestResponse<Boolean> updateFeedback(@RequestBody PersonalTarget personalTarget) {
        Boolean ret = personalTargetService.updateFeedback(personalTarget);
        return RestResponse.data(ret);
    }

    /**
     * 个贷估价对象删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = personalTargetService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 计算开关
     * @param isOnline
     * @param id
     * @return
     */
    @GetMapping("/switch/{isOnline}/{id}")
    public RestResponse<Boolean> calculateSwitch(@PathVariable("isOnline") Boolean isOnline,@PathVariable("id") Long id){
        boolean update = personalTargetService.update(new LambdaUpdateWrapper<PersonalTarget>().set(PersonalTarget::getIsOnline, isOnline).eq(BaseEntity::getId, id));
        return RestResponse.data(update);
    }

    /**
     * 个贷估价对象更新 房产证
     */
    @PutMapping("/houseCertificate")
    public RestResponse<Boolean> houseCertificate(@RequestBody PersonalHouseCertificateVO houseCertificateVO) {
        Boolean ret = personalTargetService.houseCertificate(houseCertificateVO);
        return RestResponse.data(ret);
    }
    /**
     * 个贷估价对象更新 国土证
     */
    @PutMapping("/landCertificate")
    public RestResponse<Boolean> landCertificate(@RequestBody PersonalLandCertificateVO landCertificateVO) {
        Boolean ret = personalTargetService.landCertificate(landCertificateVO);
        return RestResponse.data(ret);
    }
    /**
     * 个贷估价对象更新 不动产权证
     */
    @PutMapping("/immovableCertificate")
    public RestResponse<Boolean> immovableCertificate(@RequestBody PersonalImmovableCertificateVO immovableCertificateVO) {
        Boolean ret = personalTargetService.immovableCertificate(immovableCertificateVO);
        return RestResponse.data(ret);
    }

    /**
     * 个贷估价对象更新 实物状况
     */
    @PutMapping("/entityInfo")
    public RestResponse<Boolean> entityInfo(@RequestBody PersonalEntityInfoVO  entityInfoVO) {
        Boolean ret = personalTargetService.entityInfo(entityInfoVO);
        return RestResponse.data(ret);
    }

    /**
     * 个贷估价对象更新 区位状况
     */
    @PutMapping("/backgroundInfo")
    public RestResponse<Boolean> backgroundInfo(@RequestBody PersonalBackgroundInfo backgroundInfo) {
        Boolean ret = personalTargetService.backgroundInfo(backgroundInfo);
        return RestResponse.data(ret);
    }

    /**
     * 个贷估价对象更新 变现能力分析
     */
    @PutMapping("/sellingAbility")
    public RestResponse<Boolean> sellingAbility(@RequestBody PersonalSellingAbilityVO  sellingAbilityVO) {
        Boolean ret = personalTargetService.sellingAbility(sellingAbilityVO);
        return RestResponse.data(ret);
    }

    /**
     * 个贷客户反馈
     */
    @FinishTask
    @PutMapping("/doFeedback")
    public RestResponse<Boolean> doFeedback(@RequestBody TaskRecordDTO<PersonalTarget> taskRecordDTO) {
        Boolean ret = personalTargetService.doFeedback(taskRecordDTO);
        return RestResponse.data(ret);
    }

    /**
     * 模糊匹配区位状况
     * @param location
     * @return
     */
    @PostMapping("/bg/fuzzy")
    public RestResponse<List<PersonalBackgroundInfo>> fuzzyBackgroundList(String location){
        List<PersonalBackgroundInfo> result = personalTargetService.fuzzyBackgroundList(location);
        return RestResponse.data(result);
    }

}

