package com.cool.bang.modules.business.controller;

import com.cool.bang.common.base.BaseController;
import com.cool.bang.common.constant.ControllerConstant;
import com.cool.bang.common.web.request.PageDomain;
import com.cool.bang.common.web.response.Result;
import com.cool.bang.common.web.response.module.ResultTable;
import com.cool.bang.modules.business.domain.JobButler;
import com.cool.bang.modules.business.service.IJobButlerService;
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.*;

/**
 * 管家服务
 *
 * @author Sy
 * @version 1.0.0
 * 2024-11-13 17:25
 */
@RestController
@RequestMapping(ControllerConstant.BUSINESS + "butler/v1")
public class JobButlerController extends BaseController {

    private IJobButlerService jobButlerService;

    @Autowired
    public JobButlerController(IJobButlerService jobButlerService) {
        this.jobButlerService = jobButlerService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','business:butler:main')")
    public ResultTable main(PageDomain pageDomain, JobButler param) {
        PageInfo<JobButler> jobButlerPage = jobButlerService.page(pageDomain, param);
        return pageTable(jobButlerPage.getList(), jobButlerPage.getTotal());
    }

    @GetMapping("{id}")
    @PreAuthorize("hasPermission('','business:butler:main')")
    public Result get(@PathVariable Long id) {
        return success(jobButlerService.queryById(id));
    }

    @PostMapping
    @PreAuthorize("hasPermission('','business:butler:add')")
    public Result add(@RequestBody JobButler jobButler) {
        jobButler.insertConfigure();
        return decide(jobButlerService.save(jobButler));
    }

    @PostMapping("edit")
    @PreAuthorize("hasPermission('','business:butler:add')")
    public Result edit(@RequestBody JobButler jobButler) {
        return decide(jobButlerService.update(jobButler));
    }

    @DeleteMapping("{id}")
    @PreAuthorize("hasPermission('','business:butler:add')")
    public Result remove(@PathVariable Integer id) {
        return decide(jobButlerService.removeById(id));
    }

}
