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

import com.neusoft.smart.pos.dto.org.request.OrgQueryRequest;
import com.neusoft.smart.pos.dto.org.request.PostOrgRequest;
import com.neusoft.smart.pos.dto.org.request.PutOrgRequest;
import com.neusoft.smart.pos.dto.org.response.PostOrgResponse;
import com.neusoft.smart.pos.framework.bean.PaginationExtendBean;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.org.service.OrgService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/org")
public class OrgController {
    @Resource
    OrgService orgService;

    @GetMapping("/my")
    public ResponseData<PostOrgResponse> getMyOrg(String username) {
        return new ResponseData<>(orgService.selectOrgByUsername(username));
    }
    
    @GetMapping("/list")
    public ResponseData<PaginationExtendBean<PostOrgResponse>> getOrgList(OrgQueryRequest orgQueryRequest) {
    	PaginationExtendBean<PostOrgResponse> orgsResponse = new PaginationExtendBean<>();
    	orgsResponse.setRows(orgService.selectOrgsByCondi(orgQueryRequest));
    	orgsResponse.setTotal(orgService.countOrgsByCondi(orgQueryRequest));
    	return new ResponseData<>(orgsResponse);
    }
    
    @GetMapping("/detail")
    public ResponseData<PostOrgResponse> getOrgDetail(@RequestParam("orgId") int orgId) {
        return new ResponseData<>(orgService.selectOrgById(orgId));
    }
    
    @PostMapping("/insert")
    public ResponseData<PostOrgResponse> orgInsert(@RequestBody PostOrgRequest orgRequest){
    	return new ResponseData<>(orgService.insertOrg(orgRequest));
    }
    
    @PutMapping("/update")
    public ResponseData<Integer> orgUpdate(@RequestBody PutOrgRequest putOrgRequest){
    	return new ResponseData<>(orgService.updateOrg(putOrgRequest));
    }
    
    @DeleteMapping("/delete")
    public ResponseData<Integer> orgDelete(int orgId){
    	return new ResponseData<>(orgService.deleteOrg(orgId));
    }
}
