package com.enterprise.manage.modules.asset.controller;

import com.enterprise.manage.common.base.BaseController;
import com.enterprise.manage.common.web.request.PageDomain;
import com.enterprise.manage.common.web.response.Result;
import com.enterprise.manage.common.web.response.module.ResultTable;
import com.enterprise.manage.modules.asset.domain.EnterpriseNameChange;
import com.enterprise.manage.modules.asset.service.IEnterpriseNameChangeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 企业机构更名记录 Controller
 *
 * @author QingLi Wang
 * @version 1.0.0
 * 2023-11-28 09:32
 */
@RestController
@RequestMapping("/asset/change/v1")
public class EnterpriseNameChangeController extends BaseController {

    private IEnterpriseNameChangeService enterpriseNameChangeService;

    @Autowired
    public EnterpriseNameChangeController(IEnterpriseNameChangeService enterpriseNameChangeService) {
        this.enterpriseNameChangeService = enterpriseNameChangeService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','change:asset:list')")
    public ResultTable list(PageDomain pageDomain, EnterpriseNameChange param) {
        PageInfo<EnterpriseNameChange> enterpriseNameChangePage = enterpriseNameChangeService.page(pageDomain, param);
        return pageTable(enterpriseNameChangePage.getList(), enterpriseNameChangePage.getTotal());
    }

    @GetMapping("{id}")
    @PreAuthorize("hasPermission('','change:asset:list')")
    public Result get(@PathVariable Long id) {
        return success(enterpriseNameChangeService.queryById(id));
    }

    @PostMapping
    @PreAuthorize("hasPermission('','change:asset:add')")
    public Result add(EnterpriseNameChange enterpriseNameChange) {
        return decide(enterpriseNameChangeService.save(enterpriseNameChange));
    }

    @PutMapping
    @PreAuthorize("hasPermission('','change:asset:edit')")
    public Result edit(EnterpriseNameChange enterpriseNameChange) {
        return decide(enterpriseNameChangeService.update(enterpriseNameChange));
    }

    @DeleteMapping("{id}")
    @PreAuthorize("hasPermission('','change:asset:del')")
    public Result remove(@PathVariable Integer id) {
        return decide(enterpriseNameChangeService.removeById(id));
    }

}
