package com.neusoft.smart.pos.org.controller;

import com.neusoft.smart.pos.dto.org.response.PostOrgGroupResponse;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.org.service.OrgGroupService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/orgGroup")
public class OrgGroupController {
    @Resource
    OrgGroupService orgGroupService;

    
    @GetMapping("/parents")
    public ResponseData<List<PostOrgGroupResponse>> getOrgGroupParents(@RequestParam("entity") String entity, @RequestParam("id") int id) {
        return new ResponseData<>(orgGroupService.getOrgGroupParents(entity, id));
    }
    @ApiOperation(value = "Id is OrgGroup ID if entity is empty,")
    @GetMapping("/my")
    public ResponseData<PostOrgGroupResponse> getOrgGroupSelf(@RequestParam("entity") String entity, @RequestParam("id") int id) {
        return new ResponseData<>(orgGroupService.selectOrgGroupById(entity, id));
    }

    @GetMapping("/parentsCount")
    public ResponseData<Integer> getParentsCount(@RequestParam("entity") String entity, @RequestParam("id") int id) {
        return new ResponseData<>(orgGroupService.countParentsByCondi(entity, id));
    }

    @GetMapping("/isChild")
    public ResponseData<Boolean> getIsChild(@RequestParam("entity") String entity, @RequestParam("id") int id, @RequestParam("parentId") int parentId) {
        return new ResponseData<>(orgGroupService.isChildOfParent(entity, id, parentId));
    }

    @PutMapping("/update")
    public ResponseData<Integer> update(@RequestParam("entity") String entity, @RequestParam("id") int id, @RequestParam("status") String status){
    	return new ResponseData<>(orgGroupService.updateOrgGroupStatus(entity, id, status));
    }
}
