package com.zksy.controller.property;

import com.zksy.property.domain.AContractInfo;
import com.zksy.property.domain.dto.ContractFormDTO;
import com.zksy.property.domain.dto.ReceiptDto;
import com.zksy.property.domain.dto.ReturnReceiptDto;
import com.zksy.property.service.AContractInfoService;
import com.zksy.utils.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project enterprise-assets-service
 * @description 合同信息控制层
 * @date 2025/6/24 14:33:13
 */
@RestController
@RequestMapping("/acontractInfo")
@Api(tags = "合同信息",description = "合同信息desc")
public class AContractInfoController {
    @Autowired
    private AContractInfoService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "合同信息查询分页")
    public AjaxResult findByPage(long pageNum, long pageSize, String contractNumber,String contractDate,String contractStatus){
        return AjaxResult.success(service.findByPage(pageNum, pageSize, contractNumber,contractDate,contractStatus));
    }
    @GetMapping("/getAContractInfoList")
    @ApiOperation(value = "合同信息查询")
    public AjaxResult getAContractInfoList(String contractNumber,String contractDate,String contractStatus){
        return AjaxResult.success(service.getAContractInfoList(contractNumber,contractDate,contractStatus));
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据Id查询合同信息")
    public AjaxResult getById(@PathVariable String id){
        return AjaxResult.success(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "合同信息保存")
    public AjaxResult save(@RequestBody AContractInfo entity) {
        return service.save(entity) ? AjaxResult.success(entity) : AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "合同信息修改")
    public AjaxResult update(@RequestBody AContractInfo entity) {
        entity.setUpdateTime(LocalDateTime.now());
        return service.updateById(entity) ? AjaxResult.success(entity) : AjaxResult.error("修改失败");
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "合同信息删除")
    public AjaxResult delete(@RequestBody String[] ids) {
        return service.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }

    @GetMapping("/getBySimplifiedHouseId")
    @ApiOperation(value = "根据 simplifiedHouseId 查询合同信息")
    public AjaxResult getBySimplifiedHouseId(String simplifiedHouseId){
        return AjaxResult.success(service.getBySimplifiedHouseId(simplifiedHouseId));
    }

    @PostMapping("/signContract")
    @ApiOperation(value = "合同信息签约")
    public AjaxResult signContract(@RequestBody ContractFormDTO dto) {
        return AjaxResult.success(service.signContract(dto));
    }

    @GetMapping("/returnRent")
    @ApiOperation(value = "退租")
    public AjaxResult returnRent(String houseId) {
        return AjaxResult.success(service.returnRent(houseId));
    }

    @PostMapping("/uploadSignContract")
    @ApiOperation(value = "上传签约合同")
    public AjaxResult uploadSignContract(String contractId, MultipartFile file) {
        return AjaxResult.success(service.uploadSignContract(contractId,file));
    }


    @GetMapping("/canBeDetReceiptData")
    @ApiOperation(value = "可被获取的收据数据")
    public AjaxResult canBeDetReceiptData(String contractId) {
        return AjaxResult.success(service.canBeDetReceiptData(contractId));
    }

    @PostMapping("/getReceipt")
    @ApiOperation(value = "获取收据")
    public AjaxResult getReceipt(String contractId, @RequestBody ReceiptDto dto) {
        return AjaxResult.success("成功开具",service.getReceipt(contractId, dto));
    }

    @GetMapping("/canBeDetReturnReceiptData")
    @ApiOperation(value = "可被获取的退据数据")
    public AjaxResult canBeDetReturnReceiptData(String contractId) {
        return AjaxResult.success(service.canBeDetReturnReceiptData(contractId));
    }

    @PostMapping("/getReturnReceipt")
    @ApiOperation(value = "获取退据")
    public AjaxResult getReturnReceipt(String contractId, @RequestBody ReturnReceiptDto dto) {
        return AjaxResult.success("成功开具",service.getReturnReceipt(contractId,dto));
    }

}
