package com.dayou.controller;

import com.dayou.dto.TaskRecordDTO;
import com.dayou.vo.CompareExampleVO;
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.IPersonalCalculateService;
import com.dayou.entity.PersonalCalculate;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 个贷可比实例算价表
 *
 * @author wucl
 * @since 2024-03-01
 */
@RestController
@RequestMapping("personalCalculate")
@Slf4j
public class PersonalCalculateController extends BaseController {
    @Autowired
    private IPersonalCalculateService personalCalculateService;

    /**
    * 个贷可比实例算价表列表
    */
    @GetMapping("")
    public RestResponse<Page<PersonalCalculate>> page(PersonalCalculate personalCalculate, Page page){
        Page<PersonalCalculate> pages=personalCalculateService.selectPage(page,personalCalculate);
        return RestResponse.data(pages);
    }

    /**
     * 个贷可比实例算价表详情
     */
    @GetMapping("/{id}")
    public RestResponse<PersonalCalculate> detail(@PathVariable Long id){
        PersonalCalculate xPersonalCalculate =personalCalculateService.detail(id);
        return RestResponse.data(xPersonalCalculate);
     }

    /**
     * 个贷可比实例算价表新增
     */
    @FinishTask
    @PostMapping("/calculate")
    public RestResponse<Boolean> calculateSave(@RequestBody @Valid TaskRecordDTO<CompareExampleVO> taskRecordDTO) {
        Boolean ret = personalCalculateService.calculate(taskRecordDTO);
        return RestResponse.data(ret);
    }

    /**
     * 个贷可比实例算价表更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody PersonalCalculate personalCalculate) {
        Boolean ret = personalCalculateService.update(personalCalculate);
        return RestResponse.data(ret);
    }

    /**
     * 个贷可比实例算价表删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = personalCalculateService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 查询计算结果
     * @return
     */
    @GetMapping("/result/{targetId}")
    public RestResponse<CompareExampleVO> calculateResult(@PathVariable("targetId") Long targetId){
        CompareExampleVO result = personalCalculateService.calculateResult(targetId);
        return RestResponse.data(result);
    }

}

