/*
 * Copyright ©2023 CJB-CNIT Team. All rights reserved
 */
package com.openhis.web.paymentmanage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.core.common.core.domain.R;
import com.openhis.financial.domain.Contract;
import com.openhis.financial.service.IContractService;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 付款合同管理
 *
 * @author SunJQ
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/payment/contract")
@Slf4j
@AllArgsConstructor
public class PaymentContractController {

    @Autowired
    private IContractService contractService;

    /**
     * 查询租户合同信息分页
     *
     * @param tenantId 租户ID
     * @param pageNum 当前页
     * @param pageSize 每页条数
     * @return 租户合同信息分页
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:operate')")
    @GetMapping("/page")
    public R<IPage<Contract>> getTenantContractPage(@RequestParam Integer tenantId,
        @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return R.ok(contractService.getTenantContractPage(tenantId, pageNum, pageSize));
    }

    /**
     * 查询租户合同信息详情
     *
     * @param id 合同ID
     * @return 租户合同信息详情
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:operate')")
    @GetMapping("/{id}")
    public R<Contract> getTenantContractDetail(@PathVariable Long id) {
        return R.ok(contractService.getTenantContractDetail(id));
    }

    /**
     * 新增租户合同信息
     *
     * @param contract 合同管理实体
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:operate')")
    @PostMapping
    public R<?> addTenantContract(@RequestBody Contract contract) {
        contractService.addTenantContract(contract);
        return R.ok();
    }

    /**
     * 编辑租户合同信息
     *
     * @param contract 合同管理实体
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:operate')")
    @PutMapping
    public R<?> editTenantContract(@RequestBody Contract contract) {
        contractService.editTenantContract(contract);
        return R.ok();
    }

    /**
     * 删除租户合同信息
     *
     * @param id ID
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:operate')")
    @DeleteMapping("/{id}")
    public R<?> delTenantContract(@PathVariable Long id) {
        contractService.delTenantContract(id);
        return R.ok();
    }

}
