package cn.ey.biz.module.system.controller.admin.contract.v2;

import cn.ey.biz.common.pojo.PageResult;
import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.controller.admin.contract.v2.vo.ContractFieldVO;
import cn.ey.biz.module.system.service.contract.ContractArchivedFieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "合同管理 - 合同归档字段")
@RestController
@RequestMapping("/system/contract/archived")
@Validated
public class ContractArchivedFieldController {


    @Autowired
    private ContractArchivedFieldService contractArchivedFieldService;

    @PostMapping("/field")
    @ApiOperation("添加修改合同归档字段")
    @PreAuthorize("@ss.hasPermission('system:contract:modify')")
    public R<?> saveContractArchivedField(@Validated(value = ContractFieldVO.Add.class)
                                          @RequestBody ContractFieldVO field) {
        contractArchivedFieldService.saveContractArchivedField(field);
        return R.success(null);
    }

    @DeleteMapping("/field")
    @ApiOperation("删除合同字段")
    @PreAuthorize("@ss.hasPermission('system:contract:modify')")
    public R<?> deleteContractArchivedField(@Validated(value = ContractFieldVO.Delete.class)
                                            @RequestBody ContractFieldVO field) {
        contractArchivedFieldService.deleteContractArchivedField(field);
        return R.success(null);
    }

    @PostMapping("/field/page")
    @ApiOperation("分页获取合同字段")
    @PreAuthorize("@ss.hasPermission('system:contract:get')")
    public R<PageResult<ContractFieldVO>> getContractArchivedFieldPage(@RequestBody ContractFieldVO page) {
        return R.success(contractArchivedFieldService.getContractArchivedFieldByPage(page));
    }

    @PostMapping("/field/sl")
    @ApiOperation("获取业务线合同字段")
    @PreAuthorize("@ss.hasPermission('system:contract:get')")
    public R<PageResult<ContractFieldVO>> getContractArchivedFieldPageBySl(@Validated(value = ContractFieldVO.Select.class)
                                                                           @RequestBody ContractFieldVO info) {
        return R.success(contractArchivedFieldService.getContractArchivedFieldPageBySl(info));
    }


    @PostMapping("/field/show")
    @ApiOperation("修改是否展示")
    @PreAuthorize("@ss.hasPermission('system:contract:get')")
    public R<PageResult<ContractFieldVO>> changeShow(@Validated(value = ContractFieldVO.Update.class)
                                                     @RequestBody ContractFieldVO info) {
        contractArchivedFieldService.changeShow(info);
        return R.success(null);
    }

    @PostMapping("/field/input")
    @ApiOperation("修改是否必填")
    @PreAuthorize("@ss.hasPermission('system:contract:get')")
    public R<PageResult<ContractFieldVO>> changeInput(@Validated(value = ContractFieldVO.Update.class)
                                                      @RequestBody ContractFieldVO info) {
        contractArchivedFieldService.changeInput(info);
        return R.success(null);
    }

    @PostMapping("/field/default")
    @ApiOperation("修改默认值")
    @PreAuthorize("@ss.hasPermission('system:contract:get')")
    public R<PageResult<ContractFieldVO>> changeValue(@Validated(value = ContractFieldVO.Update.class)
                                                      @RequestBody ContractFieldVO info) {
        contractArchivedFieldService.changeDefaultValue(info);
        return R.success(null);
    }

}
