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

import com.enterprise.manage.common.base.BaseController;
import com.enterprise.manage.common.web.request.PageDomain;
import com.enterprise.manage.common.web.response.module.ResultTable;
import com.enterprise.manage.modules.system.domain.po.Regional;
import com.enterprise.manage.modules.system.service.IRegionalService;
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.*;
import com.enterprise.manage.common.web.response.Result;

/**
 * 地区信息 Controller
 *
 * @author PeiZhi Guo
 * @version 1.0.0
 * 2023-11-28 16:09
 */
@RestController
@RequestMapping("/system/regional/v1")
public class RegionalController extends BaseController {

    private IRegionalService regionalService;

    @Autowired
    public RegionalController(IRegionalService regionalService) {
        this.regionalService = regionalService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','sys:regional:main')")
    public ResultTable list(PageDomain pageDomain, Regional param) {
        PageInfo<Regional> regionalPage = regionalService.page(pageDomain, param);
        return pageTable(regionalPage.getList(), regionalPage.getTotal());
    }

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

    @PostMapping
    @PreAuthorize("hasPermission('','sys:regional:add')")
    public Result add(Regional regional) {
        return decide(regionalService.save(regional));
    }

    @PutMapping
    @PreAuthorize("hasPermission('','sys:regional:edit')")
    public Result edit(Regional regional) {
        return decide(regionalService.update(regional));
    }

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

    @GetMapping("parentId/{parentId}")
    @PreAuthorize("hasPermission('','sys:regional:main')")
    public Result queryRegionalByParentId(@PathVariable Long parentId) {
        return success(regionalService.queryRegionalByParentId(parentId));
    }



}
