package com.sptg.estate.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.estate.api.dto.UserFeedbackDto;
import com.sptg.estate.api.entity.UserFeedback;
import com.sptg.estate.api.feigns.UserFeedbackFeign;
import com.sptg.estate.biz.service.CarServiceInterface;
import com.sptg.estate.biz.service.UserFeedbackServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
public class UserFeedbackController implements UserFeedbackFeign {
    private final UserFeedbackServiceInterface userFeedbackServiceInterface;
    private final CarServiceInterface carServiceInterface;

    @Override
    @PostMapping(value = "/userFeedback/pagingQuery")
    public ResultBean<Page<UserFeedback>> pagingQuery(@RequestBody UserFeedbackDto userFeedbackDto) {
        return this.userFeedbackServiceInterface.pagingQuery(userFeedbackDto);
    }

    @Override
    @PostMapping(value = "/userFeedback/add")
    public ResultBean<Boolean> add(@RequestBody UserFeedbackDto userFeedbackDto) {
        return this.userFeedbackServiceInterface.add(userFeedbackDto);
    }

    @Override
    @PostMapping(value = "/userFeedback/handle")
    public ResultBean<Boolean> handle(@RequestBody UserFeedbackDto userFeedbackDto) {
        return this.userFeedbackServiceInterface.handle(userFeedbackDto);
    }

    @Override
    @GetMapping(value = "/userFeedback/getOne")
    public ResultBean<UserFeedback> getOne(@RequestBody UserFeedbackDto userFeedbackDto) {
        return this.userFeedbackServiceInterface.getOne(userFeedbackDto);
    }

    @Override
    @GetMapping(value = "/userFeedback/getById/{id}")
    public UserFeedback getById(@PathVariable(value = "id") Long id) {
//        Wrapper<Car> wrapper = new EntityWrapper<>();
//        List<Car> carList = carServiceInterface.selectList(wrapper);
//        try{
//            String encryptKey = "ad84afc60ddae8a8";
//            for(Car car : carList){
//                if(car.getEncrypt() != 1){
//                    if(StringUtils.hasText(car.getVehicleDrivingLicense1())){
//                        car.setVehicleDrivingLicense1(AESPlus.encrypt(encryptKey, car.getVehicleDrivingLicense1()));
//                    }
//                    if(StringUtils.hasText(car.getVehicleDrivingLicense2())){
//                        car.setVehicleDrivingLicense2(AESPlus.encrypt(encryptKey, car.getVehicleDrivingLicense2()));
//                    }
//                    car.setEncrypt(1);
//                    carServiceInterface.updateById(car);
//                }
//            }
//        }catch (Exception e){
//
//        }
        return this.userFeedbackServiceInterface.selectById(id);
    }
}
